I have a servlet, i want to passing some value from that servlet to an applet.
The flow is somekind like this
- an applet calling a servlet
- servlet gave some values to the applet
- applet retrieve a value from the servlet.
this is my applet code :
public void start() {
URL url = new URL(getCodeBase(), getParameter("URL"));
System.out.println("opening url : " + url);
URLConnection con = url.openConnection();
con.setDoInput(true);
DataInputStream obIn = new DataInputStream(con.getInputStream());
System.out.println("dataInputStream : " + obIn);
System.out.println("servlet Values : " + obIn.readInt());
}
the URL value it takes from the applet.html
and this is my servlet code :
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException {
DataOutputStream dos = new DataOutputStream(res.getOutputStream());
dos.writeInt(100);
dos.close();
}
the result that i found in the java console was, something like this
dataInputStream : java.io.DataInputStream@9abc69
servlet Values : 1010792557
and i'm already wrote the servlet name in web.xml like this
<servlet-mapping>
<servlet-name>MyApplet</servlet-name>
<url-pattern>/MyApplet</url-pattern>
</servlet-mapping>
this thing got me to a stressed, how come the applet cannot recieve the values from the servlet??
is there anything wrong with my code? or is that something config that i'm missing?
right now im using Spring, jsf and tomcat 7.0.20
Thanks a lot for your help.
Regards
Albert.