Create a new Java Web Application project. Create a ServletContextListener which
ID: 3691279 • Letter: C
Question
Create a new Java Web Application project.
Create a ServletContextListener which gets the current time as a String and stores it as a servlet context attribute (application scope bean) named something like "servletLoadTime".
Create a Filter which gets the current time for each request and sets a session attribute (session scoped bean) named something like "sessionOpenTime" as long as it does not already exist.
Create another Filter which gets the current time for each request and sets it as a request attribute named something like "requestReceivedTime".
Create a JSP which displays the servlet load time, session open time, and request received time.
Explanation / Answer
Ans;
run the below jsp file you will get the example session attributes program.
if you would like to add extra methods you can add like
getMaxInactiveInterval(),invalidate(),setMaxInactiveInterval(int interval) .... etc.
-------------------------------------------------------
<%@ page import="java.io.*,java.util.*" %>
<%
Date Creation_Time = new Date(session.getCreationTime());
Date Requested_Time = new Date(session.getLastAccessedTime());
%>
<html>
<head>
<title>Session examples</title>
</head>
<body>
<center>
<h1>Session exeample methods</h1>
</center>
<table border="1" align="center" color="blue">
<tr>
<td>sessionOpenTime</td>
<td><% out.print(Creation_Time); %></td>
</tr>
<tr>
<td>Request recieved time</td>
<td><% out.print(Requested_Time); %></td>
</tr>
</table>
</body>
</html>
----------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.