Hello Devs,


In this tutorial, we are going to learn about JSP pageContext Implicit Object. In JSP, pageContext is an instance of javax.servlet.jsp.PageContext.

Example of pageContext Implicit Object

index.html

<!DOCTYPE html>
<html>
<head>
<title>pageContext Implicit Object</title>
</head>
<body>
<form action="process.jsp">
<input type="text" placeholder="first name" name="userid"> <br><br>
<input type="text" placeholder="last name" name="password"> <br> <br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>

process.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP PagContext </title>
</head>
<body>
<%
String userid=request.getParameter("userid");
String password=request.getParameter("password");
out.println("Hello :"+userid);
pageContext.setAttribute("UserName", userid, PageContext.SESSION_SCOPE);
pageContext.setAttribute("UserPassword", password, PageContext.SESSION_SCOPE);
%>
</body>
</html>

display.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP PagContext </title>
</head>
<body>
<%
String username= (String) pageContext.getAttribute("UserName", PageContext.SESSION_SCOPE);
String userpassword= (String) pageContext.getAttribute("UserPassword", PageContext.SESSION_SCOPE);
out.println("Hi "+username+" you enter");
out.println("<br><br>");
out.println("Userid :"+username);
out.println("<br>");
out.println("Password :"+userpassword);
%>
</body>
</html>


I hope this example helps you.