getSession(false) is not null on first request
Hi everyone,
I got a weird problem with the session.
In my servlet, i have something like this:
if((req.getSession(false)) ==null)
{
dest="/WEB-INF/docs/authentication/login.jsp";
req.setAttribute("oriUrl",req.getRequestURL());
}
The getSession(false) always return something not null which is not what i expect. I though when this method is FIRST called on a new request, it will return null. Am i missing anything?
Thai
# 1
No, you're right; when called with false, if the session doesn't exist, it'll return null:
getSession
public HttpSession getSession(boolean create)Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.
To make sure the session is properly maintained, you must call this method before the response is committed.
Parameters:
true - to create a new session for this request if necessary; false to return null if there's no current session
Returns:
the HttpSession associated with this request or null if create is false and the request has no valid session
See Also:
getSession()
http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getSession(boolean)
Maybe you're doing something that causes creation of the session before?
# 5
No, the request go to a front controller then the front controller forward the request to a jsp page. What i notice is that when the controller first receives the request, a session is created right away. In my web.xml. there is a session config section but it's just to set the max valid time for the session. I did tried to delete it but the session is still created .