Servlet not sending jsessionid to an applet after first response
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jack_thiyla
Posted On:   Thursday, October 30, 2008 07:08 PM

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{    More>>

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,

   <<Less
About | Sitemap | Contact