WEB ESSENTIAL Lab Record Final
WEB ESSENTIAL Lab Record Final
Completion of
Record Work
Performing the
the
Knowledge
experiment
(5 Marks)
Attendance
(5 Marks)
Technical
(5 Marks)
(5 Marks)
Faculty
S.No Date Name of the experiment with Date
4
Handling Multimedia Content In Web Sites
1
IT3401-WEB
ExNo:1
AIM:
To write a program for creation of interactive web sites - design using html and
authoring tools
ALGORITHM:
1. Create an HTML file for the home page of the web site. Use the <head> element to
include metadata, such as the title and description of the web site, as well as links to
external CSS and JavaScript files.
2. Use the <header> element to create a header section at the top of the web page.
Include a logo, navigation menu, and any other relevant information.
3. Use the <main> element to create the main content area of the web page. Use
headings and paragraphs to organize the content.
4. Use the appropriate HTML form elements to allow users to input and submit data,
such as text fields, radio buttons, checkboxes, and submit buttons.
5. Use CSS to style the web page, including the layout, colors, typography, and
multimedia content.
PROGRAM:
Web.html
<html>
<head>
<title> MSAJCE</title>
<frameset cols=20%,*>
2
IT3401-WEB
<frame src="nav.html" name="nav">
<frame src="detail.html" name="detail">
</frameset>
</head>
</html>
Head.html
<html>
<head>
<title> head </title>
<style>
body
{ margin: 0;
}
.left {
position: absolute;
left:850px;
top:0px;
}
p{ color:wh
ite;
text-shadow:2px 2px 5px black;
#h{
font-size: 25px;
font-style: oblique;
}
3
IT3401-WEB
</style>
</head>
<body>
<div class="container">
<img src="logo1.jpg" width="100%" height="100%">
<div class="left">
</html>
Nav.html
<html>
<head>
<title> navigation </title>
<style>
body
{ margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
4
IT3401-WEB
width: 100%;
background-color: #f1f1f1;
position: fixed;
height: 100%;
overflow: auto;
cursor: pointer;
}
li a{ display:block;
color:#000;
padding:8px 16px;
text-decoration:none;
}
li a.active{
background-color:#5DB7BD;
color:white;
}
li a:hover:not(.active)
{
background-color:#555;
color:white;
}
</style>
</head>
<body>
<a href="webpage.html" target="nav"></a>
<div id="myDIV">
5
IT3401-WEB
<ul>
<li><a class=" active" href="detail.html" target="detail"> HOME </li></a>
<li><a href="about.html" target="detail"> ABOUT US </li></a>
</div>
</body>
</html>
Detail.html
<html>
<head>
<title> Detail </title>
<style>
#dept{
font-size: 25px;
background: #00FF00;
padding: 20px;
color:white; width:700;
6
IT3401-WEB
border-radius:10px;
}
#login{
font-size: 25px;
background: #33EECC;
padding: 20px;
color:white;
width:400;
height:230;
border-radius:10px;
}
.bottum{
font-size: 20px;
background: #0000CC;
padding: 20px;
color:white;
}
ul #d{
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
position: fixed;
height: 100%;
overflow: auto;
color:white;
}
7
IT3401-WEB
li #d
{ display:block;
color:#000;
padding:8px 16px;
text-decoration:none;
cursor: pointer;
}
#l{ color:b
lue;
cursor:pointer;
text-align:center;
border-color:blue;
border-radius:5px;
}
#c{ color:
red;
border-color:red;
cursor:pointer;
text-align:center;
border-radius:5px;
}
.a{
font-size:35px;
}
</style>
</head>
<body bgcolor="#A7D0FE">
8
IT3401-WEB
<img src="logo2.jpg" width="10% height="10%">
<center>
<h3>MOHAMAD SATHAK A.J. COLLEGE OF ENGINEERING
<br>Siruseri,chennai-603103<br>
[email protected]</h3>
</center>
<br>
<div align="center" id="login">
<div class="a">Student Login</div><br>
<form>
User name:<input type="text" name="name" size="30"><br><br>
Password :<input type="password" name="pass" size="30"><br><br>
  <input type="submit" id="l" value=" Login ">    
  <input type="button" id="c" value=" Cancle ">
</form>
</div>
<br><br>
<font size="6" color="blue"><b> DEPARTMENTS </b></font>
<div id="dept">
<div>UG </div>
<ul id="d">
<li>COMPUTER SCIENCE AND ENGINEERING</li>
<li>INFORMATION TECHNOLOGY</li>
<li>ELECTRICAL AND ELECTRONICAL ENGINEERING</li>
<li>ELECTRICAL AND COMMUNICATION ENGINEERING</li>
<li>CIVIL ENGINEERING</li>
<li>MECHANICAL ENGINEERING</li>
9
IT3401-WEB
</div>
<br><br>
<div class="bottom">
Address
<br>
msajce.office@g
mail.com
</div>
</body>
</html>
10
IT3401-WEB
OUTPUT
RESULT:
Thus, the above program was executed and verified.
11
IT3401-WEB
ExNo:2
AIM:
To write a program for form validation using java script
ALGORITHM:
PROGRAM:
valid.html
<html>
<head>
<script type=’text/javascript’>
Function formValidation()
{
12
IT3401-WEB
var uid = document.form1.userid;
if(userid_validation(uid,5,12))
if(userid_validation(passid,7,12))
if(allLetter(uname))
if(alphanumeric(uadd))
if(allnumeric(uzip))
if(ValidateEmail(uemail))
if(validsex(umsex,ufsex))
}}}}}}}
13
IT3401-WEB
return false;
} function userid_validation(uid,mx,my)
uid.focus();
return false;
return true;
function passid_validation(passid,mx,my)
passid.focus();
return false;
return true;
function allLetter(uname)
14
IT3401-WEB
{
if(uname.value.match(letters))
return true;
else
uname.focus();
return false;
function alphanumeric(uadd)
if(uadd.value.match(letters))
return true;
else
uadd.focus();
15
IT3401-WEB
return false;
function allnumeric(uzip)
if(uzip.value.match(numbers))
return true;
else
uzip.focus();
return true;
function ValidateEmail(uemail)
if(uemail.value.match(mailformat))
return true;
16
IT3401-WEB
else
uemail.focus();
return false;
function validsex(umsex,ufsex)
{ X=
0;
if(umsex.checked)
{ X+
+;
} if(ufsex.checked)
{ X+
+;
If(x==0)
alert(‘Select Male/Female’);
umsex.focus();
return false;
else
17
IT3401-WEB
{
Window.location.reload()
return true;
</script>
</head>
<body>
<tr>
<td>User id </td>
</tr>
<tr>
<td>Password</td>
</tr>
<tr>
<td>Name</td>
</tr>
18
IT3401-WEB
<tr>
<td>Address</td>
</tr>
<tr>
<td>Country</td>
<td><select>
<option value=”India”>India</option>
<option value=”Afghanistan”>Afghanistan</option>
<option value=”usa”>usa</option>
<option value=”germany”>germany</option>
<option value=”italy”>italy</option>
</select>
</td>
</tr>
<tr>
</tr>
<tr>
<td>Email</td>
</tr>
<tr>
19
IT3401-WEB
<td>Sex</td>
</tr>
<tr>
<td>Language</td>
</tr>
<tr>
<td> About<br></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
20
IT3401-WEB
OUTPUT:
RESULT:
21
IT3401-WEB
ExNo:3
AIM:
To write a html and PhP to demonstrate invoking a PHP from a html
ALGORITHM:
1. Start the program
2. Open a Notepad
3. Write your PHP code inside the opening and closing PHP tags.
4. Save the file with a .php extension, such as "filename.php".
5. Upload the file to your Xampp folder.
6. To run the script, navigate to the URL where the script is located in a web browser.
7. Stop the program
PROGRAM:
phpform.html
<html>
<body>
<h1>Invoke Simple PHP from HTML Form </h1>
<form method="post" action="http://localhost/phpform.php">
Name: <input type="text" name="name"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
phpform.php
<html>
<head>
<title>Simple PHP</title>
</head>
<body>
<h1>Invoke Simple PHP from HTML Form </h1>
<?php
$name = $_POST['name'];
echo "Welcome, " . $name . "!";
?>
</body>
</html>
22
IT3401-WEB
STEPS TO RUN PHP PROGRAM:
1. Create a new file with a ".php" extension in the "htdocs" folder located in the
XAMPP installation directory.
2. Save the PHP file in the "htdocs" folder with an appropriate name. For example,
"myphpfile.php".
3. Open your web browser and type "localhost/filename.php" in the address bar. Replace
"filename" with the name of your PHP file. Press "Enter" to run the PHP program.
4. OR Open the html file.
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
23
IT3401-WEB
ExNo:4
AIM:
ALGORITHM:
1. Create a basic web page layout using HTML and CSS, including any necessary
containers or elements for displaying the multimedia content.
2. Create HTML tags to display the multimedia content. For images, use the img tag, for
videos use the video tag, and for audio use the audio tag.
3. Actions you want to perform on them (e.g. play, pause, stop, mute, etc.).
4. Test your program by running the HTML file in a web browser and interacting with
the multimedia content.
PROGRAM:
<html>
<head>
<style>
body
background-color: lightpink;
.a
24
IT3401-WEB
margin-left: 150px;
margin-bottom: 250px;
.b
margin-left: 150px;
margin-bottom: 250px;
</style>
</head>
<body>
<div class="a">
<br>
<h2>rockit.mp3</h2>
<audio controls>
</audio>
</br>
<br>
<h2>Kalimba.mp3</h2>
<audio controls>
25
IT3401-WEB
<source src="kalimba.ogg" type="audio/ogg">
</audio>
</br>
<br>
<h2>sleepaway.mp3</h2>
<audio controls>
</audio>
</br>
</div>
<div class="b">
</video>
</div>
</body>
</html>
26
IT3401-WEB
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
27
IT3401-WEB
ExNo:5(A)
AIM:
ALGORITHM:
PROGRAM:
MyServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
28
IT3401-WEB
public class MyServlet extends HttpServlet
String n = request.getParameter("name");
String e = request.getParameter("email");
response.setContentType("text/html");
out.println("<html>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
servlet.html
<html>
<body>
<form action="http://localhost:8080/examples/servlets/servlet/MyServlet"
method="post">
<label for="name">Name:</label>
29
IT3401-WEB
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
</form>
</body>
</html>
Web.xml:
<servlet>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/servlets/servlet/MyServlet</url-pattern>
</servlet-mapping>
1. D:\Javac MyServlet.java
2. Copy the class file and paste into - C:\xampp\tomcat\webapps\examples\WEB-
INF\classes
3. Change the web.xml
4. http://localhost:8080/examples/servlets/servlet/MyServlet
30
IT3401-WEB
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
31
IT3401-WEB
ExNo:5(B)
AIM:
ALGORITHM:
Hidden fields:
1. Create a html file which contains user information.
2. The first servlet will receive these values.
3. First servlet stores them in the hidden form fields.
4. The second servlet will display the user information with greeting message.
PROGRAM:
sessionindex.html
<html>
<body>
<h2> <center>Session Tracking using Hidden form Fields
</center></h2>
<form action="http://localhost:8080/examples/servlets/servlet/FirstServlet">
<CENTER>Name:<input type="text" name="userName"/><br/> <br>
<input type="submit" value="go"/>
</CENTER>
</form>
</body>
</html>
FirstServlet.java
import java.io.*;
import javax.servlet.*;
32
IT3401-WEB
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response){ try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
}catch(Exception e){System.out.println(e);}
}
}
SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
{ try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//Getting the value from the hidden field
String n=request.getParameter("uname");
out.print("Hello "+n);
out.close();
}catch(Exception
e){ System.out.printl
33
IT3401-WEB
n(e);
}
}
}
Web.xml
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>SecondServlet</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/servlets/servlet/FirstServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SecondServlet</servlet-name>
<url-pattern>/servlets/servlet/SecondServlet</url-pattern>
</servlet-mapping>
34
IT3401-WEB
STEPS TO RUN SERVLET PROGRAM:
1. D:\Javac MyServlet.java
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
35
IT3401-WEB
ExNo:5(C)
AIM:
ALGORITHM:
HitCounterServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HitCounterServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
HttpSession session = request.getSession(true);
Integer count = (Integer)session.getAttribute("hitCount");
if(count == null) {
count = new Integer(0);
}
count++;
session.setAttribute("hitCount", count);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
36
IT3401-WEB
out.println("<head><title>Hit Counter</title></head>");
out.println("<body>");
out.println("<h1>Hit Counter</h1>");
out.println("<p>You have visited this page " + count + " times.</p>");
out.println("Your Session ID: " + session.getId());
out.println("<br>Session Creation Time: " + new Date(session.getCreationTime()));
out.println("<br>Time of Last Access: " + new Date(session.getLastAccessedTime()));
out.println("</body></html>");
out.close();
}
}
1. D:\Javac MyServlet.java
2. Copy the class file and paste into - C:\xampp\tomcat\webapps\examples\WEB-
INF\classes
3. Change the web.xml
4. http://localhost:8080/examples/servlets/servlet/ HitCounterServlet
OUTPUT
37
IT3401-WEB
After Refresh Page
RESULT:
Thus, the above program was executed and verified.
38
IT3401-WEB
ExNo:6
AIM:
To write a program for creation of information retrieval system using web, PHP and
MYSQL
ALGORITHM:
PROGRAM:
db.html
<html>
<body>
</form>
</body>
</html>
39
IT3401-WEB
db.php
<?php
if(isset($_POST['submit']))
$uname= $_POST['name'];
$upass= $_POST['password'];
$hostname="localhost";
$dbname="employee";
if(!$conn)
else
echo "Connected";
if(mysqli_query($conn, $query))
echo "inserted";
40
IT3401-WEB
else
if (mysqli_num_rows($result)>0 ) {
while($row = mysqli_fetch_assoc($result)) {
else {
mysqli_close($conn);
?>
1. Create a new file with a ".php" extension in the "htdocs" folder located in the
XAMPP installation directory.
2. Save the PHP file in the "htdocs" folder with an appropriate name. For example,
"myphpfile.php".
3. Open your web browser and type "localhost/filename.php" in the address bar. Replace
"filename" with the name of your PHP file. Press "Enter" to run the PHP program.
4. OR Open the html file.
41
IT3401-WEB
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
42
IT3401-WEB
ExNo:7
AIM:
To write a program for creation of personal information system using java scripts.
ALGORITHM:
1. Define the data structure for the personal information. This could be a set of fields
such as name, email, phone number, etc.
2. Create an HTML form to collect the personal information from the user.
3. Write JavaScript code to validate the form data and handle form submission. This
should include error checking to ensure that all required fields are filled out correctly.
4. Create views to display the personal information to the user. This could include a
profile page that shows all of the user's information, as well as pages to display
subsets of the information such as contact details or employment history.
5. Use JavaScript to retrieve the personal information from the database and populate
the views.
6. Add functionality to allow the user to edit or delete their personal information.
7. Test the system to ensure that it works correctly and is secure.
PROGRAM:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "Personal";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
43
IT3401-WEB
// Add new person to the database
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$gender= $_POST['gender'];
$zipcode= $_POST['zipcode'];
$country= $_POST['country'];
$language=$_POST['language'];
$languages_str = implode(", ", $language);
$feedback= $_POST['feedback'];
$sql = "INSERT INTO person (name, email, phone, address, gender, zipcode, country,
language, feedback) VALUES ('$name', '$email', '$phone', '$address', '$gender', '$zipcode',
'$country', '$languages_str', '$feedback')";
if (mysqli_query($conn, $sql)) {
echo "New person added successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
44
IT3401-WEB
<title>Personal Information System</title>
</head>
<body>
<h1>Personal Information System</h1>
<label>Email:</label><br>
<input type="email" name="email" required><br>
<label>Phone:</label><br>
<input type="text" name="phone" required><br>
<label>Address:</label><br>
<input type="text" name="address" required><br>
<label>Gender:</label>
<input type="radio" name="gender" id="male" value="male" required>
<label>Male</label>
<input type="radio" name="gender" id="female" value="female" required>
<label>Female</label>
<input type="radio" name="gender" id="other" value="other" required>
<label>Other</label><br><br>
<label >Zipcode:</label>
<input type="text" name="zipcode" id="zipcode" required><br><br>
<label >Country:</label>
45
IT3401-WEB
<select name="country" id="country" required>
<option value="">Select a country</option>
<option value="USA">USA</option>
<option value="Canada">Canada</option>
<option value="UK">UK</option>
<option value="Australia">Australia</option>
<option value="India">India</option>
</select><br><br>
<label>Language:</label>
<input type="checkbox" name="language[]" id="english" value="English">
<label>English</label>
<input type="checkbox" name="language[]" id="spanish" value="Spanish">
<label>Spanish</label>
<input type="checkbox" name="language[]" id="french" value="French">
<label>French</label><br><br>
<label>Feedback:</label><br>
<textarea name="feedback" id="feedback"></textarea><br><br>
46
IT3401-WEB
<th>Gender</th>
<th>Zipcode</th>
<th>Country</th>
<th>Language</th>
<th> Feedback</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['gender']; ?></td>
<td><?php echo $row['zipcode']; ?></td>
<td><?php echo $row['country']; ?></td>
<td><?php echo $row['language']; ?></td>
<td><?php echo $row['feedback']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
47
IT3401-WEB
OUTPUT:
RESULT:
Thus, the above program was executed and verified.
48
IT3401-WEB
CONTENT BEYOND SYLLABUS
ExNo:8
AIM:
To create a database with user information and books information. The books catalogue
should be dynamically loaded from the database using JSP.
PROCEDURE:
Step 5: Retrieve the data from database and display the output
PROGRAM:
home.html
<html>
<head>
<title>Home Page</title>
<meta charset="UTF-8">
</head>
<body>
<div class="hmpg">
<br>
49
IT3401-WEB
<form method="POST" action="jsp/add.jsp">
</form>
</button></form>
</div>
</body>
</html>
Index.html
<html>
<head>
<title>Book Bank</title>
<meta charset="UTF-8">
</head>
<body>
<br>
50
IT3401-WEB
<br>
</div>
</body>
</html>
Login.html
<html>
<head>
<title>Login</title>
<meta charset="UTF-8">
</head>
<body>
<div id="dfrm1">
</form>
</div>
</body>
51
IT3401-WEB
</html>
Register.html
<html>
<head>
<title>Registration</title>
<meta charset="UTF-8">
</head>
<body>
<div>
</form>
</div>
</body>
</html>
Ret.html
<!DOCTYPE html>
52
IT3401-WEB
<!--
-->
<!DOCTYPE html>
<html>
<head>
<title>Return Book</title>
</head>
<body>
</form>
</body>
</html>
Add.jsp
<%--
Document : newjspReturn
Author : WhysoseriousONI
53
IT3401-WEB
--%>
<!DOCTYPE html>
<html>
<head>
<title>Add Book</title>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
arr.add(temp);
} catch (Exception e)
{ out.println(e);
54
IT3401-WEB
}
%>
</head>
<body>
<%
out.println("<table>");
out.println("<tr>");
out.println("<h1><th>Author<th>BookName<th>Price<th>quantity</h1>");
out.println("</tr>");
%>
<%out.println("</td>"); %>
<%out.println("</tr>"); %>
<%}
out.println("</tr>");
out.println("</table>");
%>
</body>
</html>
55
IT3401-WEB
Catlog.jsp
<!DOCTYPE html>
<html>
<head>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
arr.add(temp);
} catch (Exception e)
{ out.println(e);
%>
56
IT3401-WEB
<title>Available books</title>
</head>
<body>
<%
out.println("<table>");
out.println("<tr>");
out.println("<h1><th>Author<th>BookName<th>Price<th>Quantity<th>buy</h1>");
out.println("</tr>");
%>
<%
int qu = Integer.parseInt(asd[3]);
if (qu != 0) {
%>
<%out.println("<td>");%><a
href="http://localhost:8080/book_bank/jsp/conform.jsp?book=<%=asd[1]%>&price=<%=as
d[2]%>&qua=<%=asd[3]%>"> BUY </a>
<%out.println("</td>"); %>
<%out.println("</tr>"); %>
<% } %>
57
IT3401-WEB
<%out.println("</td>"); %>
<%out.println("</tr>"); %>
<% } %>
<%}
out.println("</tr>");
out.println("</table>");
%>
</body>
</html>
Checkout.jsp
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/asd","root","");
String email=request.getParameter("email");
PreparedStatement ps =conn.prepareStatement(check);
ps.setString(1, email);
58
IT3401-WEB
ps.setString(2,request.getParameter("pswd"));
ResultSet rs=ps.executeQuery();
if(rs.next())
String ccard=request.getParameter("ccard");
String cvv=request.getParameter("cvv");
String expd=request.getParameter("exp");
PreparedStatement psp=conn.prepareStatement(sql);
psp.setString(1,email );
psp.setString(2,book);
psp.setString(3,ccard);
psp.setString(4,cvv );
psp.setString(5,expd );
psp.setString(6, price);
psp.executeUpdate();
String num=Integer.toString(Integer.parseInt(qua)-1);
PreparedStatement bk=conn.prepareStatement(bookUpd);
bk.setString(1,num);
bk.setString(2,book);
bk.setString(3,price);
bk.executeUpdate();
59
IT3401-WEB
response.sendRedirect("http://localhost:8080/book_bank/home.html");
else
} catch (Exception e)
{ out.print(e);
%>
Conform.jsp
<!DOCTYPE html>
<html>
<head>
<title>Check Out</title>
</head>
<body>
<div>
</div>
60
IT3401-WEB
<%
String book=request.getParameter("book");
String price=request.getParameter("price");
String quan=request.getParameter("qua");
%>
</form>
</body>
</html>
Del.jsp
<!DOCTYPE html>
61
IT3401-WEB
<html>
<head>
<title>Return Book</title>
<%
String email=request.getParameter("mail");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, request.getParameter("mail"));
ResultSet rs = ps.executeQuery();;
while (rs.next())
{ arr.add(rs.getString("book")
);
} catch (Exception e)
{ out.println(e);
%>
</head>
<body>
62
IT3401-WEB
<h1><b>
<%
out.println("<table>");
out.println("<tr>");
out.println("<h1><th>BookName");
out.println("</tr>");
<% out.println("<td>");%>
<%=arr.get(i) %>
<a
href="http://localhost:8080/book_bank/jsp/returnform.jsp?book=<%=arr.get(i)%>&mail=<%
= email%>"> Return </a>
<%out.println("</tr>"); %>
<% } %>
<% out.println("<br>");%>
<% out.println("</table>");%>
</b></h1>
</body>
</html>
Loginpage.jsp
<%
try {
Class.forName("com.mysql.jdbc.Driver");
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, mai);
ps.setString(2, pass);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
response.sendRedirect("http://localhost:8080/book_bank/home.html");
} else {
<html>
<body>
<h1>
</h1>
</body>
</html>
<%}
} catch (Exception e)
{ out.println(e);
64
IT3401-WEB
%>
Register.jsp
<%
try
String name=request.getParameter("nm1");
String mai=request.getParameter("ea1");
String pass=request.getParameter("ps1");
Class.forName("com.mysql.jdbc.Driver");
Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/asd","root","");
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, mai);
ps.setString(3, pass);
int s=ps.executeUpdate();
out.println(s);
if(s==1)
response.sendRedirect("http://localhost:8080/book_bank/login.html");
else
{
65
IT3401-WEB
out.println("Error occured in registering");
catch(Exception e)
out.println(e);
%>
Request.jsp
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<h1>requst</h1>
</body>
</html>
Returnform.jsp
<%@page import="java.net.ConnectException"%>
<!DOCTYPE html>
66
IT3401-WEB
<html>
<head>
<title>Return Book</title>
<%
String book=request.getParameter("book");
String email=request.getParameter("mail");
try
Class.forName("com.mysql.jdbc.Driver");
Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/asd","root","");
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, book );
ps.setString(2, email);
ps.executeUpdate();
PreparedStatement qs=conn.prepareStatement(getQua);
qs.setString(1, book);
ResultSet rs=qs.executeQuery();
String qn="";
while(rs.next())
qn=rs.getString("quantity");
67
IT3401-WEB
}
String upbl="update book set quantity=? where name=?";
PreparedStatement psp=conn.prepareStatement(upbl);
psp.setString(1,Integer.toString(Integer.parseInt(qn)+1));
psp.setString(2, book);
psp.executeUpdate();
catch(Exception e)
out.println(e);
%>
</head>
<body>
<h1><b>Book Returned</b></h1>
</body>
</html>
Newcss.css
#wpd1a
text-align: center;
font-size: 50px;
#lg1hd
68
IT3401-WEB
{
#frm1{
text-align: justify;
font-size: 50px;
margin-left: 50px;
#submitid{
text-align: center;
font-size: 50px;
.hmpg
text-align: center;
font-size: 100px;
text-height: 100px;
table,th,td{
font-size: 20px;
69
IT3401-WEB
OUTPUT:
Welcome page
Login page
Register page
70
IT3401-WEB
On
login
Book catalog
Lend Book
71
IT3401-WEB
On clicking buy
Return book
72
IT3401-WEB
return
On successful return
RESULT:
73
IT3401-WEB
ExNo:9
AIM:
PROCEDURE:
HTML
Step 1: Write a html file which contains a form that is directed to a servlet
SERVLET
<html>
<body>
<h2>ONLINE EXAMINATION</h2>
74
IT3401-WEB
<h3>Answer the following questions (5 marks for each correct answer)</h3>
<br/><br/>
<br/><br/>
<br/><br/>
</form>
</body>
</html>
OnlineExam.java
import java.io.*;
import java.util.*;
75
IT3401-WEB
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
response.setContentType("text/html");
try {
Class.forName("com.mysql.jdbc.Driver");
String sql;
ResultSetrs = stmt.executeQuery(sql);
String first=request.getParameterById("ans1");
String second=request.getParameterById("ans2");
String third=request.getParameterById("ans3");
out.println("<html><body>");
while(rs.next())
76
IT3401-WEB
String one1 =rs.getString("one");
if(one1.equals(first))
else
if(two2.equals(second))
else
if(three3.equals(third))
else
out.println("</body></html>");
rs.close();
stmt.close();
conn.close();
catch(SQLException se)
{ se.printStackTrace();
77
IT3401-WEB
catch(Exception e) {
e.printStackTrace();
OUTPUT:
78
IT3401-WEB