Write a web application for a online support 20 of a video library. This application should have the following features :
You are required to use the following tables for your online video library.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>Add new Customer : </div>
<form action="AddNewCustomer" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Name : <input type="text" name="name" value="" /><br/>
Address : <input type="text" name="address" value="" /><br/>
Registration date : <input type="text" name="reg_date" value="" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddNewCustomer extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String name = req.getParameter("name");
String address = req.getParameter("address");
String reg_date = req.getParameter("reg_date");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into customer values(?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setString(2, name);
st.setString(3, address);
st.setString(4, reg_date);
st.executeUpdate();
con.close();
out.write("<h1>Customer Added to system</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if(ex.getMessage().contains("General error"))
out.write("Id value is already used.");
}
}
}
============================================================================
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>Add video to library : </div>
<form action="AddNewVideo" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Name : <input type="text" name="name" value="" /><br/>
Genre : <input type="text" name="genre" value="" /><br/>
Year of Release : <input type="text" name="year_of_release" value="" /><br/>
Total Copies : <input type="text" name="Copies" value="" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddNewVideo extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String name = req.getParameter("name");
String genre = req.getParameter("genre");
String year_of_release = req.getParameter("year_of_release");
String Copies = req.getParameter("Copies");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into video_info values(?,?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setString(2, name);
st.setString(3, genre);
st.setInt(4, Integer.parseInt(year_of_release));
st.setInt(5, Integer.parseInt(Copies));
st.executeUpdate();
con.close();
out.write("<h1>Video added to library</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if(ex.getMessage().contains("General error"))
out.write("Id value is already used.");
}
}
}
====================================================================================
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>check_in / check_out: </div>
<form action="in_out" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Customer Id : <input type="text" name="cust_id" value="" /><br/>
Video Id:<input type="text" name="video_id" value="" /><br/>
operation :<select name="operation">
<option>Check-In</option>
<option>Check-Out</option>
</select><br/>
transfer date : <input type="text" name="trans_date" value="<%= new java.util.Date() %>" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class in_out extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String cust_id = req.getParameter("cust_id");
String video_id = req.getParameter("video_id");
String operation = req.getParameter("operation");
String trans_date = req.getParameter("trans_date");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into trans values(?,?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setInt(2, Integer.parseInt(cust_id));
st.setInt(3, Integer.parseInt(video_id));
st.setString(4, operation);
st.setString(5, trans_date);
st.executeUpdate();
st.close();
con.close();
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
Statement st1 = con.createStatement();
ResultSet rs = st1.executeQuery("select total_copies from video_info where id=" + video_id);
rs.next();
int n = rs.getInt(1);
if (operation.equalsIgnoreCase("Check-In")) {
n++;
int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
} else {
n--;
int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
}
con.close();
out.write("<h1>Transfer operation completed</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if (ex.getMessage().contains("General error")) {
out.write("Id value is already used.");
}
}
}
}
==============================================================================
view status
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import ="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Status</title>
</head>
<body>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from video_info");
String tr = "";
while (rs.next()) {
tr = tr + "<tr>";
tr = tr + "<td>" + rs.getString(1) + "</td>";
tr = tr + "<td>" + rs.getString(2) + "</td>";
tr = tr + "<td>" + rs.getString(3) + "</td>";
tr = tr + "<td>" + rs.getString(4) + "</td>";
tr = tr + "<td>" + rs.getString(5) + "</td>";
tr = tr + "</tr>";
}
String table = "<table border='1'><tr><td>ID</td><td>Name</td><td>Genre</td><td>Year Of Release</td><td>Total Copies</td></tr>" + tr + "</table>";
out.write(table);
con.close();
} catch (Exception e) {
out.write("" + e);
}
%>
</body>
</html>
======================================================================================
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Welcome to video library application</h1>
<a href="ViewStatus.jsp">View Status</a>, <a href="addCustomer.html">Add Customer</a>, <a href="addvideo.html">Add New Video</a>, <a href="chechkin_checkout.jsp">Checkin/Checkout</a>
</body>
</html>
- Add a new video information in the library.
- Check in / check out process for renting purpose.
- Status report containing the current
- status of videos in the library.
You are required to use the following tables for your online video library.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>Add new Customer : </div>
<form action="AddNewCustomer" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Name : <input type="text" name="name" value="" /><br/>
Address : <input type="text" name="address" value="" /><br/>
Registration date : <input type="text" name="reg_date" value="" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddNewCustomer extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String name = req.getParameter("name");
String address = req.getParameter("address");
String reg_date = req.getParameter("reg_date");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into customer values(?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setString(2, name);
st.setString(3, address);
st.setString(4, reg_date);
st.executeUpdate();
con.close();
out.write("<h1>Customer Added to system</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if(ex.getMessage().contains("General error"))
out.write("Id value is already used.");
}
}
}
============================================================================
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>Add video to library : </div>
<form action="AddNewVideo" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Name : <input type="text" name="name" value="" /><br/>
Genre : <input type="text" name="genre" value="" /><br/>
Year of Release : <input type="text" name="year_of_release" value="" /><br/>
Total Copies : <input type="text" name="Copies" value="" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddNewVideo extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String name = req.getParameter("name");
String genre = req.getParameter("genre");
String year_of_release = req.getParameter("year_of_release");
String Copies = req.getParameter("Copies");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into video_info values(?,?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setString(2, name);
st.setString(3, genre);
st.setInt(4, Integer.parseInt(year_of_release));
st.setInt(5, Integer.parseInt(Copies));
st.executeUpdate();
con.close();
out.write("<h1>Video added to library</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if(ex.getMessage().contains("General error"))
out.write("Id value is already used.");
}
}
}
====================================================================================
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>check_in / check_out: </div>
<form action="in_out" method="POST">
Id : <input type="text" name="id" value="" /><br/>
Customer Id : <input type="text" name="cust_id" value="" /><br/>
Video Id:<input type="text" name="video_id" value="" /><br/>
operation :<select name="operation">
<option>Check-In</option>
<option>Check-Out</option>
</select><br/>
transfer date : <input type="text" name="trans_date" value="<%= new java.util.Date() %>" /><br/>
<input type="submit" value="Add" />
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class in_out extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String id = req.getParameter("id");
String cust_id = req.getParameter("cust_id");
String video_id = req.getParameter("video_id");
String operation = req.getParameter("operation");
String trans_date = req.getParameter("trans_date");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
PreparedStatement st = con.prepareStatement("insert into trans values(?,?,?,?,?)");
st.clearParameters();
st.setInt(1, Integer.parseInt(id));
st.setInt(2, Integer.parseInt(cust_id));
st.setInt(3, Integer.parseInt(video_id));
st.setString(4, operation);
st.setString(5, trans_date);
st.executeUpdate();
st.close();
con.close();
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
Statement st1 = con.createStatement();
ResultSet rs = st1.executeQuery("select total_copies from video_info where id=" + video_id);
rs.next();
int n = rs.getInt(1);
if (operation.equalsIgnoreCase("Check-In")) {
n++;
int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
} else {
n--;
int i = con.createStatement().executeUpdate("update video_info set total_copies=" + n + " where id=" + video_id);
}
con.close();
out.write("<h1>Transfer operation completed</h1>");
} catch (Exception ex) {
ex.printStackTrace(System.out);
if (ex.getMessage().contains("General error")) {
out.write("Id value is already used.");
}
}
}
}
==============================================================================
view status
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import ="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Status</title>
</head>
<body>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/db4.mdb");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from video_info");
String tr = "";
while (rs.next()) {
tr = tr + "<tr>";
tr = tr + "<td>" + rs.getString(1) + "</td>";
tr = tr + "<td>" + rs.getString(2) + "</td>";
tr = tr + "<td>" + rs.getString(3) + "</td>";
tr = tr + "<td>" + rs.getString(4) + "</td>";
tr = tr + "<td>" + rs.getString(5) + "</td>";
tr = tr + "</tr>";
}
String table = "<table border='1'><tr><td>ID</td><td>Name</td><td>Genre</td><td>Year Of Release</td><td>Total Copies</td></tr>" + tr + "</table>";
out.write(table);
con.close();
} catch (Exception e) {
out.write("" + e);
}
%>
</body>
</html>
======================================================================================
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Welcome to video library application</h1>
<a href="ViewStatus.jsp">View Status</a>, <a href="addCustomer.html">Add Customer</a>, <a href="addvideo.html">Add New Video</a>, <a href="chechkin_checkout.jsp">Checkin/Checkout</a>
</body>
</html>
Comments