JSP pageContext object
JSP pageContext implicit object is instance of javax.servlet.jsp.PageContext.
It is used to get attribute, set attribute and remove attribute at any of the below scope–
- JSP Page – Scope: PAGE_CONTEXT
- HTTP Request – Scope: REQUEST_CONTEXT
- HTTP Session – Scope: SESSION_CONTEXT
- Application Level – Scope: APPLICATION_CONTEXT
Example of pageContext implicit object
index.html
<html>
<head>
<body>
<form action="first.jsp">
<input type="text" name="uname"><br>
<input type="text" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
first.jsp
<html> <body> <% String name=request.getParameter("uname"); String pass=request.getParameter("password"); out.println("hello "+name); pageContext.setAttribute("UName", name, PageContext.SESSION_SCOPE); pageContext.setAttribute("UPassword", pass, PageContext.SESSION_SCOPE); %> <a href="second.jsp">Go to second jsp</a> </body> </html>
second.jsp
<html>
<body>
<%
String name= (String) pageContext.getAttribute("UName", PageContext.SESSION_SCOPE);
String password= (String) pageContext.getAttribute("UPassword", PageContext.SESSION_SCOPE);
out.println("Name="+name);
out.println("Password= "+password);
%>
</body>
</html>
[…] pageContext Object […]
LikeLike