I am having a problem with Servlet sessions (e.g. JSESSIONID)
when I temporarily "exit" my program and then go back into it.
server version: 'Apache Tomcat/4.0.1'
server Platform: Microsoft Windows 2000 5.00.2195 - SP2
Internet Explorer: 5.50.4522.1800
My browser settings are enabled to allow Cookies to be stored on my
hard-drive
and per-session.
Here is some insight into what my servlet program does...
All the processing is done in the doPost() method.
My doGet() method just calls doPost(request,response)
1. The first thing I do in GetPost() is obtain the current session object,
or create one if necessary:
HttpSession session = request.getSession();
2. Then I set the content type and ServletOutputStream as you normally
would.
3. Then I check to see if I have cookie named "JSESSIONID":
Cookie cookies[] = request.getCookies();
if (cookies != null) {
for (int i=0; i < cookies.length; i++) {
String name = cookies[i].getName();
String value = cookies[i].getValue();
if (name.equalsIgnoreCase("JSESSIONID")) {
out.println("Found JSESSIONID Cookie [" + value + "]<BR>");
}
}
}
4. Then I display a very Simple METHOD=POST Form. The ACTION is set to
submit the
information to itself (e.g. the same servlet that displayed the form)
Here is what happens when I run the servlet program...
(e.g. http://localhost:8080/reportsApp/servlet/SessionServlet)
When I run the program for the very first time it does not find any cookie
named
JSESSIONID, which I would expect because no "request" has been made to the
server:
session.isNew() - is true
request.isRequestedSessionIdValid() - is false
request.getRequestedSessionId() - is null
On subsequent POST submits, it does find the cookie (as expected):
session.isNew() - is false
request.isRequestedSessionIdValid() - is true
request.getRequestedSessionId() - is something like
'657423F71534F089A594A6C164F84212'
But if I temporarily change the URL in my browser to say, www.yahoo.com and
then
change it back to my servlet program, it doesn't find the JSESSIONID cookie
the first
time it runs the program. I would have expected the JSESSIONID cookie
there.
The session hasn't timed out (I was only a few seconds on yahoo) and I did
not
shut down my browser.
I must be missing a simple concept. If anybody has any insight, I would
appreciate it.
Thanks,
Jim
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html