Details
Description
In a servlet filter, when the session is retrieved and an object added to it, upon the first request, the session object exists but is not saved with the request. upon the second request, the objects saved in the session are not there and the session is a different object. However, from the 2nd request onward, the session object is always the same.
See code:
/** Start Code **/
HttpServletRequest hsReq = ( HttpServletRequest ) request;
HttpSession session = hsReq.getSession();
System.out.println( session );
Integer num = ( Integer ) session.getAttribute( "Num" );
if ( num == null )
{
num = new Integer( 2 );
session.setAttribute( "Num", num );
System.out.println( "Was Null" );
}
/** End Code **/
This prints out:
//First request
org.mortbay.jetty.servlet.HashSessionManager$Session@1e9c82e
Was Null
//Second Request
org.mortbay.jetty.servlet.HashSessionManager$Session@14d5bc9
Was Null
//Third Request
org.mortbay.jetty.servlet.HashSessionManager$Session@14d5bc9
Notice that the third request returns the same session object and the "num" is no longer null.
I cannot reproduce this.
Can you provide a few more details please:
Thanks.