Java HttpSession

Sergey picture Sergey · Feb 28, 2011 · Viewed 32k times · Source

Is HttpSession in java servlet is created only after

HttpSession s = request.getSession();

?

In my code I didn't write that, but when I use if (request.getSession(false) == null) ..., it doesn't work. Why?

Answer

Wilhelm Kleu picture Wilhelm Kleu · Feb 28, 2011

A HttpSession is created when calling request.getSession().

But if you access a JSP by default it will automatically create a session.This behaviour can be disabled by using: <%@ page session="false">

Are you using JSP?