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 that can be accessed from one web page to another. the session is used to manage the server-side state management options.

The session always will be created by a web server and manage by browser cookies. we can create a cookieless session also to 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()

Syntax of Session in JSP:-


Syntax to destroy session object:-

HttpSession session = request.getSession()

Syntax to get data from session object?

JSP Syntax:-


Servlet Syntax:-

HttpSession session = request.getSession()

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); 

What is the advantage of Session?

1)  It provides persistent objects hence we can access session variables into multiple web pages.
2)  Session provide better page security for internal pages hence we always create session under Login Form.
3)  Session is used to display user-specific data under web pages.

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post