Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Session in JSP and Servlet:-

It is a persistent object which is used to contain the data from one web page to another.session is used to manage server-side state management option.


The session always will be created by a web server and manage by browser cookies. we can create a cookieless session also store session data under a database server.


The session is mandatory to manage user login, admin login functionality because if we want to display user-specific data after login then the session is mandatory.


If we want to provide internal page security in web applications then also we will use the session.


Syntax of Session in Servlet:-

Create Session:-

Syntax on Servlet:-

HttpSession session = request.getSession()
session.setAttribute("key","value");



Syntax of Session in JSP:-

session.setAttribute("key","value");


Syntax to destroy session object:-

HttpSession session = request.getSession()
session.removeAttribute("key");
session.inValidate()


Syntax to get data from session object?

JSP Syntax:-

session.getAttribute("key");

Servlet Syntax:-

HttpSession session = request.getSession()
session.getAttribute("key")


Note:-  By default session time interval is 30 MINUTES we can increase or decrease the session time interval from the application.

using session.setMaxInactiveInterval(600); 



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post