Aim: A web application takes a name as input and on submit it shows a hello page where is taken from the request. It shows the start time at the right top corner of the page and provides a logout button. On clicking this button, it should show a logout page with Thank You message with the duration of usage (hint: Use session to store name and time).

File: login.html

<form name="login" method="post" action="hello.jsp">
    <table width="370" border="1" align="center" style="background: silver;">
        <tr height=25>
            <th colspan="4" align="center">User Login</th>
        </tr>
        <tr>
            <td>User Name</td>
            <td><input type="text" name="uname"></td>
        </tr>
        <tr align="center">
            <td align="center" colspan="2">
                <input type="submit" name="ok" value="Submit">
            </td>
        </tr>
    </table>
</form>
        
File: hello.jsp

<%@page import="java.util.Date" %>
<%
    String uname = request.getParameter("uname");
    session.setAttribute("uname", uname);
    Date d = new Date();
    session.setAttribute("time", d.getTime());
%>
<h2 align="center">Hello <%= uname %></h2>
<h4 align="right">Start Time: <%= d %></h4><br>
<a href="thanku.jsp" align="center">Logout</a>
        
File: thanku.jsp

<%@page import="java.util.Date" %>
<%
    String uname = (String) session.getAttribute("uname");
    long startTime = (Long) session.getAttribute("time");
    Date d = new Date();
    long duration = (d.getTime() - startTime) / 1000; // Convert milliseconds to seconds
%>
<h2 align="center">Thank you <%= uname %></h2><br>
<h2 align="center">Your duration is <%= duration %> seconds</h2>
        
Output:

login.html (1)hello.jspthanku.jsp

;