Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

CSI3018-Advanced Java

Name: Mothishwaran C.

Reg No: 19MID0017

Slot: L53+L54

DA: 03- JSP

Question: Assume a driver (user) is caught by a police while violating the driving rules. Then, the police is providing him/her a
login portal and asked the driver to submit the name and age. If the age is below 18 then the police has to report as “ Warning: You are
not eligible for Driving”. Otherwise, each time the user is caught, then the police has a count on the particular user. If the user is caught
third time then the police cancel his/her driving license, reported as ”DL CANCELLED ” along with date and time. Demonstrate for atleast
three users (drivers).These activities are recorded between 5:40 PM to 6:40 PM. Develop as application for the above said scenario of
driving rule violation with suitable front-end using JSP.

Index.html:
<html>

<head>

<title>TODO supply a title</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>

body{

background-color: #FBAB7E;

background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);

display: flex;

justify-content: center;

align-items: center;

.content{

width: 40%;

height:60%;

padding: 10px;

background-color: #fff;

</style>

</head>

<body>

<div class="content">
<center>

<h1 style="color: #ff6666 ">Check Your License</h1>

<hr>

<form action="DL_Checker.jsp" method="GET">

<table>

<tr>

<td>

<b>Enter your Name: </b>

</td>

<td>

<input type="text" name ="name">

</td>

</tr>

<tr>

<td>

<b>Enter your Age: </b>

</td>

<td>

<input type="text" name ="age">

</td>

</tr>

<tr>

<td>

</td>

<td>

<input type="submit" value="Check">

</td>

</tr>

</table>

</form>

</center>

</div>

</body>

</html>
DLChecker.jsp:
<%--

Document : DL_Checker

Created on : 08-Sep-2022, 10:21:39 pm

Author : Mothish

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.time.LocalDateTime"%>

<%@page import="java.time.format.DateTimeFormatter"%>
<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

<style>

body{

background-color: #FBAB7E;

background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);

display: flex;

justify-content: center;

align-items: center;

.content{

width: 40%;

height:60%;

margin:15%;

padding: 10px;

background-color: #fff;

display: flex;

flex-direction: column;

justify-content: center;

align-items: center;

.button {

background-color: #4CAF50;

border: none;

color: white;

padding: 15px 32px;

text-align: center;

text-decoration: none;

display: inline-block;

font-size: 16px;

margin: 4px 2px;

cursor: pointer;

</style>

</head>

<body>

<div class="content">

<%

String uname=request.getParameter("name");

String udate=uname+"_date";

int age =Integer.valueOf(request.getParameter("age"));

if(age<18){
out.println("Hey "+uname+" You are not eligible!");

}else{

Integer caught_count = (Integer)session.getAttribute(uname);

if(caught_count==null){

caught_count=1;

out.println("<p style='color: #ff9933'><b>Hey "+uname+", you got your first warning..</b>");

}else{

caught_count+=1;

if(caught_count<3){

out.println("<p style='color: #ff9933'><b>Hey "+uname+", you got your second warning..</b>");

else if(caught_count==3){

LocalDateTime datetime = LocalDateTime.now();

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss");

String dtime=String.valueOf(datetime.format(formatter));

session.setAttribute(udate,dtime);

out.println("<p style='color:red'>Hey "+uname+", your Driving License is <b>cancelled</b> at "+dtime);

}else{

String cancelled_date = (String)session.getAttribute(udate);

out.println("<p style='color:red'>Hey "+uname+", your Driving License is <b>cancelled</b> on "+cancelled_date);

}}

session.setAttribute(uname,caught_count);

session.setMaxInactiveInterval(60*60);

String path =request.getContextPath();

out.println("<br><div><hr><div>");

out.println("<a class='button' href='"+path+"'> Check again</a></div><div>");

%>

</div>

</body>

</html>
Output:
User-1 :
User-1 is Elon, 17. So he got as follows.
User-2:
User -2 is Musk. He is above 18 and he got caught for 3 times.
User-3:
User-3 is Moss, 22. He got caught for 3rd time and his DL was cancelled.
User :2 re-checked
User 2, Musk re-checked after 1 minute

You might also like