You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Skidmore, Donald (GTI PE)" <Do...@ml.com> on 2006/08/01 17:28:56 UTC

Sessions in Tomcat

I am running into a strange situation with my session using tomcat 5.0.I
have a jsp that puts two objects into a session which is used by all
succeeding jsp pages. The first browser session works fine and I can
navigate thru all my pages without a problem. A few minutes later I open
another browser window and I immediately get a null pointer exception. I
traced the problem to accessing the objects in the session. The jsp that
does a session.setAttribute("test",obj) works fine. When I do a
System.out.println("Contents of obj=",obj) I get the proper value. But
when I do a session.getAttribute("test") I get a null pointer exception.
I checked Tomcat/conf/web.xml and see the session-config element set to
30 minutes. When I added to the jsp to check if the session is invalid
do a request.getSession() to create a new session I get the same
results. I finally tried going into Tomcat's manager and doing a reload.
Both browser sessions bring to work normally, the original browser
continues as if nothing happened and the second browser session loads
without the null pointer exception. Is there something I am not setting?
Even more bizarre, after I do a reload of the website if I open two
browser windows very quickly they both succeed. When I let a browser
window sit with no activity for more than two or three minutes and I
click to a link to navigate thru my jsp pages I immediately get a 
null pointer exception anywhere I am accessing the one of the session
objects. 
Here is my session entry in the web.xml
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

Any help would be appreciated.
--------------------------------------------------------

If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail.     http://www.ml.com/email_terms/
--------------------------------------------------------

Re: Sessions in Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Donald,

> The first browser session works fine and I can
> navigate thru all my pages without a problem. A few minutes later I open
> another browser window and I immediately get a null pointer exception.

Is it possible that you are have cookies turned off and are having the
JSP encode the jsessionid into each URL? If that's the case, you might
be simply typing a URL into your second browser window that doesn't have
this magic parameter, and therefore not getting a session.

> [After a restart, ] both browser sessions bring to work normally, the
> original browser continues as if nothing happened and the second
> browser session loads without the null pointer exception.

No, that's just plain weird.

> Is there something I am not setting?
> Even more bizarre, after I do a reload of the website if I open two
> browser windows very quickly they both succeed. When I let a browser
> window sit with no activity for more than two or three minutes and I
> click to a link to navigate thru my jsp pages I immediately get a 
> null pointer exception anywhere I am accessing the one of the session
> objects.

Hmm... perhaps your browser is configured to prohibit cookie life longer
than a couple of minutes??? Seems far-fetched, but you've got a weird
problem.

How are you getting your session? Can you post a bit of code? It would
be particularly useful to see the code you use to create the session, to
get the attributes (as well as verify that the session exists), and then
the place where the NPE is being thrown.

-chris