JSP session

In JSP, session object is used to establish a connection between a client and a server. It maintains the state between them so that server recognize the user easily.

The session object is an instance of servlet's HttpSession interface. This object contains the user's information and maintains the state till this session is active.

index.jsp

<html>
<head>
<title>Tutorial and Example</title>
</head>
<body>
<%
String id=session.getId();
Date d1=new Date(session.getCreationTime());
Date d2=new Date(session.getLastAccessedTime());
%>
<table>
<%="<tr><td>Session Id:</td><td>"+id+"</td></tr>"%>
<br>
<%="<tr><td>Creation Time:</td><td>"+d1+"</td></tr>"%>
<br>
<%="<tr><td>Last Accessed Time:</td><td>"+d2+"</td></tr>"%>
</table>
</body>
</html>
Output: