Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Servlet not sending JSESSIONID to applet after first response

843842Oct 30 2008 — edited Nov 3 2008
Hi all,
I am using Httpsession object for session tracking between applet and servlets. For a first applet request, the servlet creates a Httpsession object and is able to send the JSESSIONID to the applet. I extract the "Set-Cookie" header from the URLConnection and save it to a temporary variable(say var1). on the next request I sent the JSESSIONID( cookie) using the setHeader("Cookie",var1) which the servlet is able to receive and get the existing Httpsession object. Now it is this time the servlet is not being able to send the JSESSIONID to applet.I did check the headers at the applet end but it is not present. If anyone could explain why that is the case?

Below is my code:

Applet code:
try{
URL targetServlet = new URL(location + webappdir + "/" + servletname);
servletConnection = targetServlet.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches (false);

if(var1!=null) // Supposing var1 is the value extracted from the servletConnection.getHeader("Set-Cookie");
{
servletConnection.setRequestProperty("Cookie", var1);
}
servletConnection.setRequestProperty("Content-Type","application/x-java-serialized-object");
outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
}catch (IOException e){ }

servlet code for the second response:

HttpSession session = res.getSession(false);
res.setContentType("application/x-java-serialized-object");
res.setHeader("Cache-Control","no-cache"); //HTTP 1.1
res.setHeader("Pragma","no-cache"); //HTTP 1.0
res.setDateHeader ("Expires", 0); //prevents caching at the proxy server

outStream = res.getOutputStream();
outos = new ObjectOutputStream(outStream );
outos.writeObject(any serializable object)
outos.flush();


Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 1 2008
Added on Oct 30 2008
6 comments
824 views