Friday, April 17, 2009

Write a program to display the session ID, creation time, and the last accessed time of the Web page

Write a program to display the session ID, creation time, and the last accessed time of the Web page. Using session.getID, session.getCreationTime(), and session.getLastAccessedTime().

Solution:
The file used in this exercise is Expression.jsp. The file is saved in basic directory.
<html>
<head>
<title> JSP Expressions </title>
</head>
<body bgColor="white">
<h2>Simple JSP Expression</h2>
<ul><font color = “#0000FF”>
<li> <font color = “#0000FF”> Session id:<%= session.getId() %>
<li> <font color = “#0000FF”> Creation time:<%= new java.util.Date(session.getCreationTime()) %>
<li> <font color = “#0000FF”> Time of last access: " + <%= new java.util.Date(session.getLastAccessedTime())%>
</ul>
</body>
</html>
The output of the program is as shown in Figure 6.2.

Figure 6.2: Output of Expression.jsp

0 nhận xét: