Session tutorials in JSP and Servlet

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

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)