JSP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
JSP Tutorial
Introduction Introduction
Installing JDK-Windows Installing JDK-Windows
Installing JDK-Linux Installing JDK-Linux
Installing Tomcat Installing Tomcat
Simple Program in JSP Simple Program in JSP
Pre-defined Variables Pre-defined Variables
Syntax of Tags Syntax of Tags
JSP Expression Language JSP Expression Language
JSP EL Operators JSP EL Operators
EL Implicit Variables EL Implicit Variables
Scopes Scopes
Using Arrays Using Arrays
Methods Methods
JSP Elements JSP Elements
Including Beans Including Beans
JSTL Tags JSTL Tags
Custom Tags Custom Tags
Session Session in JSP
Handling Cookies Handling Cookies
JSP Application Structure JSP Application Structure
Configuring web.xml Configuring web.xml
Tomcat Configuration Tomcat Configuration
JSP Examples JSP Examples
Forums Ask Your Doubts
Feedback Feedback
 






outsourced web hosting support

Session Handling in JSP


Tutorials Jsp

Topic

How is Session Handled in JSP?



Explanation

Session Handling becomes mandatory when a requested data need to be sustained for further use. Since http protocol considers every request as a new one, session handling becomes important.

Following are some of the methods to handle session.
  • In JSP whenever a request arises the server generates a unique Session ID which is stored in the client machine.
  • Cookies store the information in the client browser
  • URL rewriting the session information is appended to the end of the URL
  • Hidden form fields the sessionID is embedded to GET and POST command.
Example1:
   <html>
   <body>
   <form method = "post" action="session2.jsp">
   <font>Username<input type = "text" name = "name"></font>gt;
   </font><br><br>
   <input type = "submit" name = "submit" value = "submit" >
   </form>
   </body>
   </html>
Example2:
    <%  
    String name = request.getParameter("name");
    if((name!=null)) 
	{
	 session.setAttribute("username",name);
      }
    %>
    <a href="session3.jsp">Continue</a>
Example3:
   <html>
   <head>
     <title>Welcome to session continued Page</title>
   </head>
   <body>
     <font>Welcome</font> <%= session.getAttribute("username") %>
   </body>
   </html>

In the first example "session1.jsp" we get the username using a form. When the form is submitted it goes to the second file session2.jsp which is called using form "action" attribute. A session attribute is set here using "session.setAttribute". In the third file "session3.jsp" the same username is displayed using "session.getAttribute".




Other Links

web hosting