JSP Assignment Library catalog Create a web application using JSP, MySQL, and th
ID: 3821808 • Letter: J
Question
JSP Assignment
Library catalog
Create a web application using JSP, MySQL, and the regular front-end technology stack (HTML, CSS, JavaScript) to allow patrons to interact with your local library’s catalog online. Your application can include client-side JavaScript to make the interface more user-friendly, but it should always perform the necessary server-side validations to protect the integrity of the library’s catalog and inventory.
Requirements
The librarian has given you the following requirements:
• The web application should include a log in and sign up page.
o Log in page should use a username and password.
o Sign up page should require the following fields: first name, last name, username, password, and password confirmation.
o There should be a JSP session running to keep track of whether the user is logged in or not.
• Any user can browse the catalog, regardless of whether they’ve signed up or logged in. In other words, there should be no session check on the page that allows browsing of the catalog.
o The user should be able to select from a list of topics that filters the books visible on the browsing screen. Filtering by a different topic than the one currently selected should fire off a query to the server - filtering should not be happening in the browser / JavaScript.
o If no topic is selected, the page should show all books.
o The following information should be shown at a minimum: Book title, book author, whether it’s available for checkout, and a way to reserve a copy.
• When they are logged in, users should be able to reserve a copy of their favorite available books from the browse catalog page. If not logged in, the user should still see the button to reserve the copy which will take them to the log in page upon click.
• There should be a page which allows logged in users to show their list of reserved books. If not logged in, trying to navigate to this page (even via a direct URL) should require the user to log in first.
Database structure
There is one SQL file attached with the assignment to create the database ‘library_catalog’ with the following structure:
‘authors’ table
Column Name Data Type Required Description
author_id int (10) yes Author ID, primary key
author_name varchar (100) yes Author full name
‘books’ table
Column Name Data Type Required Description
book_id int (10) yes Book ID, Primary key
subject_id int (10) yes Subject ID
book_name varchar (100) yes Book name
author_id int (10) yes Author ID
is_available tinyint (1) Yes If the book is available or not
‘reservations’ table
Column Name Data Type Required Description
user_id int (10) yes User ID
book_id Int (10) yes Book ID
‘topics’ table
Column Name Data Type Required Description
topic_id int (10) yes Topic ID, Primary key
topic_name varchar (200) yes Topic name
‘users’ table
Column Name Data Type Required Description
user_id int (10) yes User ID, Primary key
fname varchar (50) yes User first name
lname varchar (50) yes User Last name
username varchar (50) yes Username
password varchar (50) Yes Password
Explanation / Answer
index.html:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>techm</title>
</head>
<body>
<div id="menu">
<ul>
<li><b>HOME</b></li>
<li><a href="user143.jsp"><b>USER</b></a></li>
<li><a href="sign_up.jsp"><b>SIGN UP</b></a></li>
</ul>
</div>
</body>
</html>
sign_up.jsp:
<%@ page import = "java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>signup</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function valid()
{
var aa=document.s.unn.value;
if(aa=="")
{
alert("Enter Name");
document.s.unn.focus();
return false;
}
var a=document.s.uidd.value;
if(a=="")
{
alert("Enter User ID");
document.s.uidd.focus();
return false;
}
var b=document.s.passs.value;
if(b=="")
{
alert("Enter Password");
document.s.passs.focus();
return false;
}
var k = document.s.mobb.value;
if(k=="")
{
alert("Enter mobile number");
document.s.mobb.focus();
return false;
}
if(isNaN(k))
{
alert("Enter mobile number in numbers");
document.s.mobb.focus();
return false;
}
if(k.charAt(0)!= 9)
{
alert("Enter the correct mobile no");
document.s.mobb.focus();
return false;
}
if(k.length!=10)
{
alert("Enter 10 digits");
document.s.mobb.focus();
return false;
}
var emailfilter=/^w+[+.w-]*@([w-]+.)*w+[w-]*.([a-z]{2,4}|d+)$/i;
var m=emailfilter.test(document.s.eid.value);
if(m==false)
{
alert("Please enter a valid Email Id");
document.s.eid.focus();
return false;
}
}
</script>
</head>
<body>
<%
java.util.Date now = new java.util.Date();
String DATE_FORMAT1 = "dd/MM/yyyy";
SimpleDateFormat sdf1 = new SimpleDateFormat(DATE_FORMAT1);
String strDateNew1 = sdf1.format(now);
%>
<div id="menu">
<ul>
<li class="current"><a href="sign_up.jsp"><b>SIGN UP</b></a></li>
<li><a href="index.html"><b>BACK</b></a></li>
</ul>
</div>
</div>
<div id="content_area_top">
</div>
<div class="box"> <br>
<br>
<p>
<strong><em><font color="#990000" size="+1" face="Times New Roman"
>User Registration</font></em></strong>
<br/>
<br>
<form name="s" action="sign_up1.jsp" method="get">
<table align="center" cellpadding="10" cellspacing="10" width="400">
<tr>
<td><font face="Times New Roman" size="+1"><strong>Name</strong></font></td>
<td> <input type="text" name="unn" class="b"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong>User ID</strong></font></td>
<td> <input type="text" name="uidd" id="name"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong>Password</strong></font></td>
<td> <input type="password" name="passs" class="b"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong>Mobile</strong></font></td>
<td> <input type="text" name="mobb" class="b"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong>Email ID</strong></font></td>
<td> <input type="text" name="eidd" class="b"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong>Date</strong></font></td>
<td> <input type="text" name="date" class="b" value="<%=strDateNew1%>"></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="s" value="submit" class="b1" >
<input type="reset" name="r" value="clear" class="b1"></td>
</tr>
</table>
</form>
</div>
<div>
<img src="images/create_new_user.jpg" width="200" height="350">
</div>
</div>
<div class="cleaner">
</div>
</div>
<div id="footer">
</div>
</body>
</html>
sign_up1.jsp:
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import = "java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<html>
<head>
<title>TECHM</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
String a = request.getParameter("uidd");
String x = request.getParameter("unn");
String b = request.getParameter("passs");
String c = request.getParameter("mobb");
String d = request.getParameter("eidd");
session.setAttribute("a",a);
session.setAttribute("x",x);
session.setAttribute("b",b);
session.setAttribute("c",c);
session.setAttribute("d",d);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;
response.sendRedirect("sign_up3.jsp");
%>
</body>
</html>
sign_up2.jsp:
<%@ page import="java.sql.*"%>
<%@ page import = "java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dpaas</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="menu">
<ul>
<li class="current"><a href="sign_up.jsp"><b>SIGN UP</b></a></li>
<li><a href="index.html"><b>BACK</b></a></li>
</ul>
</div>
<div class="box"> <br>
<br>
<font color="#33CC66" size="+2" face="Times New Roman, Times, serif"><i><b>You
Are Successfully Registered</b></i></font> <br>
<br>
<a href="user.jsp"><font color="#33CCFF" size="+2" face="Times New Roman, Times, serif"><b>User
Login</b></font></a> </div>
</div>
<!-- Primary content area end -->
</div>
<div class="cleaner">
</div>
</div><!-- End Of Content area top -->
<div id="footer">
</div><!-- End Of Container -->
<!-- Free CSS Templates by freecsstemplates.in -->
</body>
</html>
sign_up3.jsp:
<%@ page import="java.sql.*" %>
<%@ page import = "java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;
String uid=null;
String a=(String)session.getAttribute("a");
String x=(String)session.getAttribute("x");
String b=(String)session.getAttribute("b");
String c=(String)session.getAttribute("c");
String d=(String)session.getAttribute("d");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/satish","root","1234");
uid="18";
PreparedStatement ps=con.prepareStatement("insert into user values(?,?,?,?,?,?,'"+strDateNew+"')");
ps.setString(1,uid);
ps.setString(2,x);
ps.setString(3,a);
ps.setString(4,b);
ps.setString(5,c);
ps.setString(6,d);
ps.executeUpdate();
//out.print(Successfully Registered);
response.sendRedirect("sign_up2.jsp");
}
catch(Exception e1)
{
out.println(e1.getMessage());
}
%>
</body>
</html>
user.jsp:
<%@ page import="java.sql.*"%>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>user</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<script type="text/javascript">
function valid()
{
var a=document.s.uid.value;
if(a=="")
{
alert("Enter User ID");
document.s.uid.focus();
return false;
}
var b=document.s.pass.value;
if(b=="")
{
alert("Enter Password");
document.s.pass.focus();
return false;
}
}
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="content_area_top">
</div>
<div class="box"> <br>
<p> <strong><font color="#990000" size="+1" face="Times New Roman"
>Admin Login</font></strong> <br/>
<br>
<form name="s" action="user1.jsp" method="get">
<table align="left" width="400" height="200" background="images/02.jpg">
<tr>
<td><font face="Times New Roman" size="+1"><strong><img src="images/Users.png" width="30" height="30"> User
ID</strong></font></td>
<td> <input type="text" name="uid" class="b"></td>
</tr>
<tr>
<td><font face="Times New Roman" size="+1"><strong><img src="images/bs.png" width="30" height="30"> Password</strong></font></td>
<td> <input type="password" name="pass" class="b"></td>
</tr>
<tr>
<td><input type="submit" name="s" value="submit" class="b1" >
<input type="reset" name="r" value="clear" class="b1"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
user1.jsp:
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
Connection con = null;
Statement st = null;
String a=request.getParameter("uid");
String b=request.getParameter("pass");
session.setAttribute("a",a);
ResultSet rs=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/satish","root","1234");
st = con.createStatement();
String qry="select * from user where userid='"+a+"' && pass='"+b+"'";
rs=st.executeQuery(qry);
if(rs.next())
{
//name2=rs.getString("name");
response.sendRedirect("user_view.jsp");
//session.setAttribute("name2",name2);
//out.print(name2);
}
else
{
out.println("enter correct user mane and password");
}
}
catch(Exception e2){
out.println(e2.getMessage());
}
%>
</body>
</html>
userview.jsp:
<%@ page import="java.sql.*"%>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dpaas</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="menu">
<ul>
<li><a href="index3.html"><b>BACK</b></a></li>
</ul>
</div>
<div class="cleaner"></div>
</div>
<div id="content_area_top">
</div>
<div class="box"> <br>
<br>
<br>
<br>
<br>
<div>
<p>
<strong><em><font color="#990000" size="+1" face="Times New Roman"
>User Registration Details</font></em></strong>
<br/>
<br>
<form name="s" action="#" method="get">
<table align="center" width="500">
<tr>
<td bgcolor="#CCCCCC"><font face="Times New Roman" size="+1"><strong>USER
NAME</strong></font></td>
<td bgcolor="#CCCCCC"><font face="Times New Roman" size="+1"><strong>USER
ID</strong></font></td>
<td bgcolor="#CCCCCC"><font face="Times New Roman" size="+1"><strong>MOBILE
NO</strong></font></td>
<td bgcolor="#CCCCCC"><font face="Times New Roman" size="+1"><strong>EMAIL</strong></font></td>
</tr>
<%
String name=null,userid=null,mobile=null,email=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/satish","root","1234");
PreparedStatement ps=con.prepareStatement("select name,userid,mobile,email from user");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
name=rs.getString(1);
userid=rs.getString(2);
mobile=rs.getString(3);
email=rs.getString(4);
//data=rs.getString(2);
%>
<tr>
<td bgcolor="#CCFFFF">
<%=name%>
</td>
<td bgcolor="#CCFFFF">
<%=userid%>
</td>
<td bgcolor="#CCFFFF">
<%=mobile%>
</td>
<td bgcolor="#CCFFFF">
<%=email%>
</td>
</tr>
<%
}
%>
<%
}
catch(Exception e1)
{
out.println(e1.getMessage());
}
%>
</table>
</form>
</div>
<!-- Primary content area end -->
</div>
<div class="cleaner">
</div>
</div><!-- End Of Content area top -->
<div id="footer">
</div><!-- End Of Container -->
<!-- Free CSS Templates by freecsstemplates.in -->
</body>
</html>
database:
user table:
CREATE TABLE `user` (
`uid` varchar(225) NOT NULL,
`name` varchar(255) NOT NULL,
`userid` varchar(255) NOT NULL,
`pass` varchar(255) NOT NULL,
`mobile` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`date` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
‘authors’ table
CREATE TABLE `authors` (
`author_id` int(225) NOT NULL,
`authour_name` varchar(255) NOT NULL,
) ;
‘books’ table:
CREATE TABLE `books` (
`book_id` int(225) NOT NULL,
`subject_id` int(225) NOT NULL,
`book_name` varchar(255) NOT NULL,
`author_id` int(225) NOT NULL,
) ;
‘reservations’ table:
CREATE TABLE `books` (
`user_id` int(225) NOT NULL,
`book_id` int(225) NOT NULL,
) ;
‘topics’ table:
CREATE TABLE `books` (
`topic_id` int(225) NOT NULL,
`topic_name` varchar(255) NOT NULL,
) ;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.