Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

JSP pageContext


In JSP, pageContext is an implicit object of type PageContext class.The pageContext object can be used to set,get or remove attribute from one of the following scopes:

  • page
  • request
  • session
  • application
In JSP, page scope is the default scope.

Example of pageContext 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. pageContext.setAttribute(“user”,name,PageContext.SESSION_SCOPE);
  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)pageContext.getAttribute(“user”,PageContext.SESSION_SCOPE);
  5. out.print(“Hello “+name);
  6. %>
  7. </body>
  8. </html>

Output

session1

session2

session3

Comments

comments