You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by Bill Boland <bo...@mediaone.net> on 2000/06/09 03:59:10 UTC
JSESSIONID not set in response header
Hello to all. This is the first time I'm contributing here. As I am using
Tomcat more and more, I'll try to contribute more and more.
Hopefully this is not just a stupid mistake that I'm doing. I am using the
Tomcat release 3.1 on Windows 2000. It is running as a stand-alone server.
It seems when I visit a JSP page on my test site that includes another JSP
page that the
session ID (set in the cookies with JSESSIONID) is never written to the
response unless I explicitly flush the "out" prior to the include. This only
happens when establishing the session Id for the first time. As I have
looked at the source, I think it has something to do with the output buffers
and/or purging of cookies during an include...but I could be wrong (just
beginning to look at source for this...there's quite a bit).
I also found out that even if you perform the out.flush() before the include
but you don't have anything in the out buffer, the response header will not
have the cookies either (including the JSESSIONID).
Maybe this has already been fixed in the latest code but I just thought
others who are using the release build (3.1) should know about this if it is
not just some idiotic thing I'm doing or can confirm that this is the case
by trying the included test case.
Here's some test code that reproduces
the problem on a vanilla Tomcat. I just placed these two JSP files at the
root, open browser and go to the http://localhost:8080/sessionTest.jsp
page. Then hit refresh over and
over again. The session id changes. So...the big question. Is this normal?
Here's the HTML source that my browser gets without flushing the output
before the include:
ID To1048mC6138599423553055At<BR>
Created: Fri Jun 02 07:52:32 PDT 2000<BR>
Last Accessed: Fri Jun 02 07:52:32 PDT 2000<BR>
test = This value should persist between sessions<BR>
<HTML>
<BODY>
ID To1048mC6138599423553055At<BR>
Created: Fri Jun 02 07:52:32 PDT 2000<BR>
Last Accessed: Fri Jun 02 07:52:32 PDT 2000<BR>
---INCLUDE---<BR>
</BODY>
</HTML>
Do the same (close browser first) with the flush line uncommented. Things
seem fine.
<HTML>
<BODY>
ID To1049mC7015872431375811At<BR>
Created: Fri Jun 02 07:56:56 PDT 2000<BR>
Last Accessed: Fri Jun 02 07:56:56 PDT 2000<BR>
---INCLUDE---<BR>
ID To1049mC7015872431375811At<BR>
Created: Fri Jun 02 07:56:56 PDT 2000<BR>
Last Accessed: Fri Jun 02 07:56:56 PDT 2000<BR>
test = This value should persist between sessions<BR>
</BODY>
</HTML>
Do the same with commenting out both the flush and the include. Things are
OK with this as well.
Source for sessionTest.jsp
---------------------------------------
<%@
page
import="java.util.*"
%>
<HTML>
<BODY>
<%
// print session info
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId() + "<BR>" );
out.println("Created: " + created + "<BR>");
out.println("Last Accessed: " + accessed + "<BR>" );
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value + "<BR>" );
}
session.setAttribute( "test", "This value should persist
between sessions" );
out.println( "---INCLUDE---<BR>" );
//out.flush();
pageContext.include( "/sessionTestInclude.jsp" );
%>
</BODY>
</HTML>
Source for sessionTestInclude.jsp
--------------------------------------------------
<%@
page
import="java.util.*"
%><%
// print session info
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId() + "<BR>" );
out.println("Created: " + created + "<BR>");
out.println("Last Accessed: " + accessed + "<BR>" );
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value + "<BR>" );
}
%>
Any ideas or help would be appreciated.
Bill Boland