Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java HttpSession

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?

like image 787
Sergey Avatar asked Feb 28 '11 10:02

Sergey


People also ask

What is HttpSession in Java?

public interface HttpSession. Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. The servlet container uses this interface to create a session between an HTTP client and an HTTP server.

Where is HttpSession stored Java?

Show activity on this post. HttpSession is a high level interface built on top of cookies and url-rewriting, which means that there is only a session ID is stored in client side and the data associated with it is stored in server side.

What is spring boot HttpSession?

The HttpSession class type lets us know which implementation (e.g. Servlet Container vs. Spring Session) is being used to manage the HTTP Session state. The HTTP Request count is simply incremented every time a client HTTP Request is made to the HTTP server (e.g. Servlet Container) before the HTTP Session expires.


2 Answers

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?

like image 96
Wilhelm Kleu Avatar answered Oct 22 '22 09:10

Wilhelm Kleu


In addition to Nishant's answer note that session can be created implicitly by JSP pages unless you configured them not to create a session with <%@ page session = "false" %>.

like image 20
axtavt Avatar answered Oct 22 '22 11:10

axtavt