Menu
- 14. A web application for implementation: The user is first served a login page which takes user's name and password. After Submitting the details the server checks these values against the data from a database and takes the following decisions.
- • If name and password matches, serves a welcome page with user's full name.
- • If name matches and password doesn't match, then serves “password mismatch” page
- • If name is not found in the database, serves a registration page, where user’s full name is asked and on submitting the full name, it stores, the login name, password and full name in the database (hint: use session for storing the submitted login name and password)
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>