Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

JSP session


In JSP, session is an implicit object of type HttpSession.The Java developer can use this object to set,get or remove attribute or to get session information.

Example of session implicit object

index.html

  1. <html>
  2. <body>
  3. <form action=“welcome.jsp”>
  4. <input type=“text” name=“uname”>
  5. <input type=“submit” value=“go”><br/>
  6. </form>
  7. </body>
  8. </html>

welcome.jsp

  1. <html>
  2. <body>
  3. <%
  4. String name=request.getParameter(“uname”);
  5. out.print(“Welcome “+name);
  6. session.setAttribute(“user”,name);
  7. <a href=“second.jsp”>second jsp page</a>
  8. %>
  9. </body>
  10. </html>

second.jsp

  1. <html>
  2. <body>
  3. <%
  4. String name=(String)session.getAttribute(“user”);
  5. out.print(“Hello “+name);
  6. %>
  7. </body>
  8. </html>

Output

session1

session2

session3

Comments

comments