Hello Devs,


In this tutorial, we are going to learn about JSP session implicit object. In JSP session is a way to store information to be used across multiple pages till the user session is active.

Example of JSP session implicit object

index.html

<!DOCTYPE html>
<html>
<head>
<title>JSP Session</title>
</head>
<body>
<form action="session-one.jsp">
<input type="text" placeholder="first name" name="fname"> <br><br>
<input type="text" placeholder="last name" name="lname"> <br> <br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>

session-one.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 Session</title>
</head>
<body>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
session.setAttribute("fname",fname);
session.setAttribute("lname",lname);
out.print("Hello"+fname);
out.print("<br>");
out.print("Session set sucessfully. Please click on the below link to check.");
%>
<br> <a href="session-two.jsp">Check</a>
</body>
</html>


session-two.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 Session </title>
</head>
<body>
<%
String fname=(String)session.getAttribute("fname");
String lname=(String)session.getAttribute("lname");
out.print("First Name :"+fname);
out.print("<br>");
out.print("Last Name :"+lname);
%>
</body>
</html>


I hope this example helps you.