You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Raimee <ra...@sympatico.ca> on 2000/10/04 15:48:20 UTC

Applet/Servlet Comm. and Sessions

I am using Tomcat 3.1b in standalone on a WinNT Workstation.

I have an html page with a link to a servlet which performs Basic
Authentication and then creates a session and binds
a database connection and login info to it.

Once this is done, the servlet performs a sendRedirect() to another html
page containing an Applet.
The applet loads and then opens a URLConnection to another servlet which
requires the session information created
in the first servlet.  A request.getSession() returns null in this
second servlet.

I know that the session is being created because I am prompted by the
browser to accept the JSessionID
cookie.

Does a URL.getConnection() request in an applet differ from an ordinary
HTML request in so much as
what HTTP Headers/cookies information is sent to the server?

Thanks,
Raimee



Re: Applet/Servlet Comm. and Sessions

Posted by Jacob Kjome <ja...@syntegra.com>.
As I understand it, you can't do a redirect and set cookies at the same 
time, which is what you are attempting to do.  That is likely your problem.

Here is a partial copy of another message that might be of some help:



Is there a problem with calling Response.sendRedirect() after 
Response.addCookie() ?


Yes, there is a bug in Tomcat 3.1 (and possibly other servlet engines). To 
send a cookie through a redirect, you must set the headers manually. 
seanm@narus.com suggests:

Cookie long_term = new Cookie(LONG_TERM_COOKIE_NAME, user_name);
long_term.setMaxAge(60*60*24*4);
long_term.setPath("/Blah");
response.addCookie(long_term); 
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location",REDIRECT_PAGE);




Hope that helps,

Jake

At 09:48 AM 10/4/2000 -0400, you wrote:
>I am using Tomcat 3.1b in standalone on a WinNT Workstation.
>
>I have an html page with a link to a servlet which performs Basic
>Authentication and then creates a session and binds
>a database connection and login info to it.
>
>Once this is done, the servlet performs a sendRedirect() to another html
>page containing an Applet.
>The applet loads and then opens a URLConnection to another servlet which
>requires the session information created
>in the first servlet.  A request.getSession() returns null in this
>second servlet.
>
>I know that the session is being created because I am prompted by the
>browser to accept the JSessionID
>cookie.
>
>Does a URL.getConnection() request in an applet differ from an ordinary
>HTML request in so much as
>what HTTP Headers/cookies information is sent to the server?
>
>Thanks,
>Raimee