Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new Java Web Application project. Create a ServletContextListener which

ID: 3691764 • 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

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>

----------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote