1
votes

I have a servlet, i want to passing some value from that servlet to an applet.

The flow is somekind like this

  1. an applet calling a servlet
  2. servlet gave some values to the applet
  3. 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.

1
i try it already with tomcat 6.0.32 it works fine at tomcat 6.0.32, so the question is, how to make it work at tomcat 7.0.20.Albert Setiadi

1 Answers

0
votes

solved,

the reason is

tomcat 7 uses HttpOnly session cookies by default (these were available in Tomcat 5.5 and 6, but were off by default). This causes problems with the Java Plugin in browsers, which doesn't get the session ID cookie and pass it through to the applet code.

i found the answer in this link Issues with Tomcat 7