Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views79 pages

WEB ESSENTIAL Lab Record Final

The document outlines a series of experiments related to web development, including creating interactive websites using HTML, form validation with JavaScript, and simple PHP scripting. Each experiment includes an aim, algorithm, and sample code demonstrating the concepts. The document also includes a grading rubric for day-to-day activities, attendance, and technical performance.

Uploaded by

nausheennazar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views79 pages

WEB ESSENTIAL Lab Record Final

The document outlines a series of experiments related to web development, including creating interactive websites using HTML, form validation with JavaScript, and simple PHP scripting. Each experiment includes an aim, algorithm, and sample code demonstrating the concepts. The document also includes a grading rubric for day-to-day activities, attendance, and technical performance.

Uploaded by

nausheennazar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Index

Marks Awarded-Day to Day


activities
Sign of

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

1 Creation Of Interactive Web Sites - Design Using


Html And Authoring Tools

2 Form Validation Using JavaScript

3 Creation Of Simple PHP Script

4
Handling Multimedia Content In Web Sites

Write programs using Servlets:


5 i.To invoke servlets from HTML forms
ii.Session tracking using hidden form fields and
Session tracking for a hit count
Creation of information retrieval system using web,
6 PHP and MySQL
Creation of personal Information System
7

CONTENT BEYOND SYLLABUS

8 Online Book catalogue using ISP

Creating three tier applications using servlet for


9 Student Mark list
Max. Marks Marks Sign of the
Internal Calculation Awarded Faculty
Average of Day to Day Activity 20
Mini Project 10
Model Exam 10
Assignment/Simulation 10
Total 60

Sign of the Student Sign of Lab In – Charge

Format No:LA 12a Rev.No:0.0 Rev.Date: 08.11.23

1
IT3401-WEB
ExNo:1

Date: CREATION OF INTERACTIVE WEB SITES - DESIGN


USING HTML AND AUTHORING TOOLS

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.

6. Publish the web site to a web server or hosting service.

PROGRAM:

Web.html
<html>
<head>
<title> MSAJCE</title>

<frameset rows=20%,* frameborder="0" border="0" framespacing="0">


<frame src="head.html" name="head">

<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">

<p id="h"> MOHAMED SATHAK A.J. COLLEGE OF ENGINEERING<br>


<style="font-size: font-color:red 20px">Siruseri,chennai-603103<br>
[email protected]</style>
</p>
</div>
</div>
</body>

</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>

<li><a href="academic.html" target="detail"> ACADEMICS </li></a>


<li><a href="admission.html" target="detail"> ADMISSION </li></a>
<li><a href="exam.html" target="detail"> EXAMINATION </li></a>

<li><a href="curricular.html" target="detail"> CO-CURRICULAR </li></a>


<li><a href="campus.html" target="detail"> CAMPUS LIFE </li></a>
<li><a href="alumini.html" target="detail"> ALUMNI </li></a>

<li><a href="place.html" target="detail"> PLACEMENT </li></a>


<li><a href="gallery.html" target="detail"> GALLERY </li></a>
</ul>

</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>
&nbsp&nbsp<input type="submit" id="l" value=" Login ">&nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp<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>

Mohamad Sathak A.J College of Engineering<br> Siruseri,


Chennai - 603103.<br>
9940004500
<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

Date: FORM VALIDATION USING JAVASCRIPT

AIM:
To write a program for form validation using java script

ALGORITHM:

1. Create an HTML form with input fields and a submit button.


2. Add the required attribute to any input fields that must be filled out before the form
can be submitted.
3. Each input field should have a unique "name" attribute.
4. Add JavaScript code to the HTML file, either in a separate file or within a <script>
tag in the <head> or <body> of the document.
5. For each input element, perform validation checks as needed (e.g. checking if it is
empty, checking if it meets a specific format, etc.).
6. If all input elements pass validation, submit the form using form.submit().

PROGRAM:

valid.html

<html>

<head>

<title>JavaScript sample registration form validation </title>

<script type=’text/javascript’>

Function formValidation()

{
12
IT3401-WEB
var uid = document.form1.userid;

var passid = document.form1.passid;

var uname = document.form1.username;

var uadd = document.form1.address;

var ucountry = document.form1.country;

var uzip = document.form1.zip;

var uemail = document.form1.email;

var umsex = document.form1.msex;

var ufsex = document.form1.fsex;

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)

var uid_len = uid.value.length;

if (uid_len == 0 || uid_len >= my || uid_len < mx)

alert(“userid should not be empty / length be between “+mx+” to “+my);

uid.focus();

return false;

return true;

function passid_validation(passid,mx,my)

var passid_len = passid.value.length;

If (passid_len == 0 ||passid_len >= my || passid_len < mx)

alert(“Password should not be empty / length be between “+mx+” to “+my);

passid.focus();

return false;

return true;

function allLetter(uname)

14
IT3401-WEB
{

var letters = /^[A-Za-z]+$/;

if(uname.value.match(letters))

return true;

else

aalert(‘Please enter your name’);

uname.focus();

return false;

function alphanumeric(uadd)

var letters = /^[0-9a-zA-Z]+$/;

if(uadd.value.match(letters))

return true;

else

alert(‘Please enter your address’);

uadd.focus();

15
IT3401-WEB
return false;

function allnumeric(uzip)

var numbers = /^[0-9]+$/;

if(uzip.value.match(numbers))

return true;

else

alert(‘Please input numeric characters for zipcode’);

uzip.focus();

return true;

function ValidateEmail(uemail)

var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if(uemail.value.match(mailformat))

return true;

16
IT3401-WEB
else

alert(“You have entered an invalid email address!”);

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
{

alert(“form submitted successfully”);

Window.location.reload()

return true;

</script>

</head>

<body>

<h1><i>REGISTRATION FORM USING JAVASCRIPT</i></h1>

<form name=’form1’ onsubmit=’return formValidation()’ >

<table width=”500” cellpadding=”3” style=”border-collapse: collapse;”>

<tr>

<td>User id </td>

<td><input type=”text” name=”userid” /></td>

</tr>

<tr>

<td>Password</td>

<td><input type=”password” name=”passid” /></td>

</tr>

<tr>

<td>Name</td>

<td><input type=”text” name=”username” /></td>

</tr>

18
IT3401-WEB
<tr>

<td>Address</td>

<td><input type=”text” name=”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>

<td>ZIP Code </td>

<td><input type=”text” name=”zip” /></td>

</tr>

<tr>

<td>Email</td>

<td><input type=”text” name=”email” size=”50” /></td>

</tr>

<tr>

19
IT3401-WEB
<td>Sex</td>

<td><input type=”radio” name=”msex” value=”Male” /> Male

<input type=”radio” name=”fsex” value=”Female” /> Female</td>

</tr>

<tr>

<td>Language</td>

<td><input type=”checkbox” name=”en” value=”en” checked />English

<input type=”checkbox” name=”nonen” value=”noen” />Non English</td>

</tr>

<tr>

<td> About<br></td>

<td><textarea name=”desc” rows=”4” cols=”40”></textarea></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input type=”submit” name=”submit” value=”Submit” /></td>

<td>&nbsp;</td>

</tr>

</table>

</form>

</body>

</html>

20
IT3401-WEB
OUTPUT:

RESULT:

Thus, the above program was executed and verified.

21
IT3401-WEB
ExNo:3

Date: CREATION OF SIMPLE PHP SCRIPTS

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

Date: HANDLING MULTIMEDIA CONTENT IN WEB SITES

AIM:

To write a program for handling multimedia content in web sites

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>

<h1>Implementation of Multimedia Content using HTML and CSS.</h1>

<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">

<h1>Audio tag in HTML</h1>

<br>

<h2>rockit.mp3</h2>

<audio controls>

<source src="rockit.ogg" type="audio/ogg">

<source src="rockit.mp3" type="audio/mpeg">

</audio>

</br>

<br>

<h2>Kalimba.mp3</h2>

<audio controls>

25
IT3401-WEB
<source src="kalimba.ogg" type="audio/ogg">

<source src="kalimba.mp3" type="audio/mpeg">

</audio>

</br>

<br>

<h2>sleepaway.mp3</h2>

<audio controls>

<source src="sleepaway.ogg" type="audio/ogg">

<source src="sleepaway.mp3" type="audio/mpeg">

</audio>

</br>

</div>

<div class="b">

<h1>Video Tag in HTML</h1>

<video width="320" height="240" controls>

<source src="video1.mp4" type="video/mp4">

<source src="video1.ogg" type="video/ogg">

</video>

</div>

</body>

</html>

26
IT3401-WEB
OUTPUT:

RESULT:
Thus, the above program was executed and verified.

27
IT3401-WEB
ExNo:5(A)

Date: WRITE PROGRAMS USING SERVLETS:

TO INVOKE SERVLETS FROM HTML FORMS

AIM:

To write a html and servlet to demonstrate invoking a servlet from a html

ALGORITHM:

1. Create a HTML form in a HTML file using the <form> tag.


2. Set the "action" attribute of the <form> tag to the URL pattern of the servlet you want
to invoke.
3. Specify the HTTP method you want to use (either GET or POST) by setting the
"method" attribute of the <form> tag.
4. Define the form fields you want to submit to the servlet using <input> tags. Give each
input field a name attribute so that you can retrieve its value in the servlet.
5. When the user submits the form, the browser will send an HTTP request to the
servlet's URL, using the specified method (GET or POST).
6. In the servlet, use the request object to retrieve the values of the form fields using
their names.
7. Process the form data as required, and generate a response using the response object.
8. Send the response back to the client.

PROGRAM:

MyServlet.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

28
IT3401-WEB
public class MyServlet extends HttpServlet

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

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

String e = request.getParameter("email");

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>");

out.println("<h1>Hello, " + n + "!</h1>");

out.println("<p>Your email address is " + e + ".</p>");

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>

<input type="email" id="email" name="email"><br><br>

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

</form>

</body>

</html>

Web.xml:

<servlet>

<servlet-name> MyServlet </servlet-name>

<servlet-class> MyServlet </servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>MyServlet</servlet-name>

<url-pattern>/servlets/servlet/MyServlet</url-pattern>

</servlet-mapping>

STEPS TO RUN SERVLET PROGRAM:

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)

Date: SESSION TRACKING USING HIDDEN FORM FIELDS

AIM:

To write a servlet program to do Session tracking using hidden form fields.

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);

//creating form that have invisible textfield


out.print("<form
action='http://localhost:8080/examples/servlets/servlet/SecondServlet'>");
out.print("<input type='hidden' name='uname' value='"+n+"'>");
out.print("<input type='submit' value='go'>");
out.print("</form>");
out.close();

}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

2. Copy the class file and paste into - C:\xampp\tomcat\webapps\examples\WEB-


INF\classes
3. Change the web.xml
4. Start the Server
5. Open the html file.

OUTPUT:

RESULT:
Thus, the above program was executed and verified.

35
IT3401-WEB
ExNo:5(C)

Date: SESSION TRACKING FOR A HIT COUNT

AIM:

To write a servlet program to do Session tracking for a hit count.

ALGORITHM:

1. Servlet program to keep track of user visiting the page.


2. The count is incremented by one when user visits.
3. The output displays the greeting message.
4. The number of previous access is also displayed.

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();
}
}

STEPS TO RUN SERVLET PROGRAM:

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

Date: CREATION OF INFORMATION RETRIEVAL SYSTEM


USING WEB, PHP AND MYSQL

AIM:

To write a program for creation of information retrieval system using web, PHP and
MYSQL

ALGORITHM:

1. Start the program


2. Design the database schema
3. Set up your development environment: You need a local server environment to run
your PHP script and MySQL database. You can use tools like XAMPP or WAMP to
set up a local development environment.
4. Create the database
5. Write the PHP code and create the web interface
6. Test your system to make sure it retrieves and displays information correctly.
7. Stop the program

PROGRAM:

db.html

<html>

<body>

<form method="post" action="http://localhost/db.php" >

Name: <input type="text" name="name"><br>

E-mail: <input type="text" name="password" ><br>

<input type="submit" value="submit" name="submit" />

</form>

</body>

</html>

39
IT3401-WEB
db.php

<?php

if(isset($_POST['submit']))

$uname= $_POST['name'];

$upass= $_POST['password'];

$hostname="localhost";

$dbname="employee";

$conn = mysqli_connect($hostname, "root", " ",$dbname) ;

if(!$conn)

echo "not coneected";

else

echo "Connected";

$query = "INSERT INTO emp (username,password) VALUES ('$uname', '$upass')";

if(mysqli_query($conn, $query))

echo "inserted";

40
IT3401-WEB
else

echo "not inserted";

$sql = "SELECT username,password FROM emp where username='$uname' ";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result)>0 ) {

// output data of each row

while($row = mysqli_fetch_assoc($result)) {

echo "name: " . $row["username"]. " -pass: " . $row["password"]. "<br>";

else {

echo "0 results";

mysqli_close($conn);

?>

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.

41
IT3401-WEB
OUTPUT:

RESULT:
Thus, the above program was executed and verified.

42
IT3401-WEB
ExNo:7

Date: CREATION OF PERSONAL INFORMATION SYSTEM

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);
}
}

// Retrieve all persons from the database


$sql = "SELECT * FROM person";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html>
<head>

44
IT3401-WEB
<title>Personal Information System</title>
</head>
<body>
<h1>Personal Information System</h1>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">


<label>Name:</label><br>
<input type="text" name="name" required><br>

<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>

<input type="submit" name="submit" value="Add Person">


</form>
<br>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>

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>

<?php mysqli_close($conn); ?>


</body>
</html>

47
IT3401-WEB
OUTPUT:

RESULT:
Thus, the above program was executed and verified.

48
IT3401-WEB
CONTENT BEYOND SYLLABUS

ExNo:8

Date: Online Book Catalogue Using JSP

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 1: Create a sql query for user and book information.

Step 2: Create a HTML form for required fields.

Step 3.Create a JSP page for processing the book information

Step 4: Start the XAMPP server to execute the program

Step 5: Retrieve the data from database and display the output

PROGRAM:

home.html

<html>

<head>

<title>Home Page</title>

<meta charset="UTF-8">

<link rel="stylesheet" href="css/newcss.css">

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

</head>

<body>

<div class="hmpg">

<br>

49
IT3401-WEB
<form method="POST" action="jsp/add.jsp">

<button type="submit" name="BookCatlog" value="BookCatlog">Book


catalogue</button><br>

</form>

<form method="POST" action="jsp/catlog.jsp">

<button type="submit" name="AddNewBook" value="AddNewBook">Lend


Book</button><br></form>

<form method="POST" action="ret.html">

<button type="submit" name="DeleteBook" value="DeleteBook">Return


Book<br>

</button></form>

</div>

</body>

</html>

Index.html

<html>

<head>

<title>Book Bank</title>

<link rel="stylesheet" href="css/newcss.css" type="text/css">

<meta charset="UTF-8">

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

</head>

<body>

<div id="wpd1a"> <h1>Welcome to Book Bank</h1>

<br>

existing user ? <a href="login.html">Sign in</a>

50
IT3401-WEB
<br>

new? <a href="register.html" >Sign up</a>

</div>

</body>

</html>

Login.html

<html>

<head>

<title>Login</title>

<meta charset="UTF-8">

<link rel="stylesheet" href="css/newcss.css" type="text/css">

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

</head>

<body>

<div id="lg1hd">Hello Book Worm!</div>

<div id="dfrm1">

<form id="frm1" action="jsp/login page.jsp" method="POST"><br>

Email ID = <input type="text" style="font-size: 25px " size= "50" name="mail"


value=""><br><br>

PassWord = <input type="password" style="font-size: 25px " size="50"


name="pswd" value=""><br><br>

<input type="submit" name="submit" id="submitid">

</form>

</div>

</body>

51
IT3401-WEB
</html>

Register.html

<html>

<head>

<title>Registration</title>

<meta charset="UTF-8">

<link rel="stylesheet" href="css/newcss.css" type="text/css">

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

</head>

<body>

<div>

<form action="jsp/register.jsp" method="POST" id="frm1">

Name : <input type="text" name="nm1" style="font-size: 25px " size="50"


value=""><br><br>

Email Address :<input type="text" style="font-size: 25px " size="50" name="ea1"


value=""><br><br>

Password :<input type="password" style="font-size: 25px " size="50" name="ps1"


value=""><br><br>

<input type="submit" name="Submit" id="submitid">

</form>

</div>

</body>

</html>

Ret.html

<!DOCTYPE html>

52
IT3401-WEB
<!--

To change this license header, choose License Headers in Project Properties.

To change this template file, choose Tools | Templates

and open the template in the editor.

-->

<!DOCTYPE html>

<html>

<head>

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

<title>Return Book</title>

</head>

<body>

<h1><b>Please Conform Your Identity</b></h1><br><br>

<form action="jsp/del.jsp" method="POST">

Email ID = <input type="text" style="font-size: 25px " size= "50" name="mail"


value=""><br><br>

<input type="submit" name="submit" id="submitid">

</form>

</body>

</html>

Add.jsp

<%--

Document : newjspReturn

Created on : Feb 22, 2020, 7:48:52 PM

Author : WhysoseriousONI

53
IT3401-WEB
--%>

<%@page contentType="text/html" import="java.util.*,java.io.*,java.sql.*" language="java"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="../css/newcss.css">

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

<title>Add Book</title>

<%

ArrayList<String> arr = new ArrayList<String>();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");

String sql = "select * from book";

PreparedStatement ps = conn.prepareStatement(sql);

ResultSet rs = ps.executeQuery();

while (rs.next()) {

String temp = rs.getString("author") + " " + rs.getString("name") + " " +


rs.getString("price")+" "+rs.getString("quantity");

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>");

for (int i = 0; i < arr.size(); i++)

{ String temp = arr.get(i);

String asd[] = temp.split(" ");

out.println("<td>" + asd[0] + "<td>" + asd[1] + "<td>" + asd[2]+"<td>"+asd[3]);

%>

<%out.println("</td>"); %>

<%out.println("</tr>"); %>

<% out.println("<br>"); %>

<%}

out.println("</tr>");

out.println("</table>");

%>

<h1><b><a href="http://localhost:8080/book_bank/jsp/catlog.jsp">Lend A Book By


Clicking here</a></b></h1>

</body>

</html>

55
IT3401-WEB
Catlog.jsp

<%@page language="java" contentType="text/html" import="java.io.*,java.util.*,java.sql.*"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="../css/newcss.css">

<%

ArrayList<String> arr = new ArrayList<String>();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");

String sql = "select * from book";

PreparedStatement ps = conn.prepareStatement(sql);

ResultSet rs = ps.executeQuery();

while (rs.next()) {

String temp = rs.getString("author") + " " + rs.getString("name") + " " +


rs.getString("price") + " " + rs.getString("quantity");

arr.add(temp);

} catch (Exception e)

{ out.println(e);

%>

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

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>");

for (int i = 0; i < arr.size(); i++)

{ String temp = arr.get(i);

String asd[] = temp.split(" ");

out.println("<td>" + asd[0] + "<td>" + asd[1] + "<td>" + asd[2] + "<td>" + asd[3]);

%>

<%

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>"); %>

<% out.println("<br>"); %>

<% } %>

<% if (qu == 0) { %>

57
IT3401-WEB
<%out.println("</td>"); %>

<%out.println("</tr>"); %>

<% out.println("<br>"); %>

<% } %>

<%}

out.println("</tr>");

out.println("</table>");

%>

</body>

</html>

Checkout.jsp

<%@page contentType="text/html" language="java" import="java.util.*,java.io.*,java.sql.*"


pageEncoding="UTF-8"%>

<%

String book = request.getParameter("book");

String price = request.getParameter("price");

String qua = request.getParameter("quantity");

try {

Class.forName("com.mysql.jdbc.Driver");

Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/asd","root","");

String email=request.getParameter("email");

String check="select * from user where email=? and pass=?";

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");

String sql="insert into order_list (email,book,ccard,cvv,exp,price) values


(?,?,?,?,?,?)";

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 bookUpd="update book set quantity=? where name=? and price=?";

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();

out.println("thank you for buying "+book+" book");

59
IT3401-WEB
response.sendRedirect("http://localhost:8080/book_bank/home.html");

else

out.println("please check email and password");

} catch (Exception e)

{ out.print(e);

%>

Conform.jsp

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

<!DOCTYPE html>

<html>

<head>

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

<title>Check Out</title>

<link rel="stylesheet" href="../css/newcss.css">

</head>

<body>

<div>

<h1> Please Verify Your Identity </h1>

</div>

60
IT3401-WEB
<%

String book=request.getParameter("book");

String price=request.getParameter("price");

String quan=request.getParameter("qua");

%>

<form id="frm1" method="POST" action="checkout.jsp">

Email:<input type="text" size="50px" style="font-size: 25px " name="email"


value=""><br>

Password:<input type="password" size="50px" style="font-size: 25px "


name="pswd" value=""><br>

Credit Card:<input type="number" style="font-size: 25px " name="ccard"


value=""><br>

CVV:<input type="password" name="cvv" style="font-size: 25px " size="50px"


value=""><br>

Expiry Date:<input type="text" name="exp" style="font-size: 25px " size="50px"


value=""><br>

<input type="hidden" value="<%=book %>" name="book" ><br>

<input type="hidden" value="<%=price %>" name="price" ><br>

<input type="hidden" value="<%=quan %>" name="quantity" ><br>

<input type="submit" value="submit" id="submitid" >

</form>

</body>

</html>

Del.jsp

<%@page contentType="text/html" language="java" import="java.io.*,java.util.*,java.sql.*"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

61
IT3401-WEB
<html>

<head>

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

<title>Return Book</title>

<%

String email=request.getParameter("mail");

ArrayList<String> arr = new ArrayList<String>();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/asd", "root", "");

String sql = "select * from order_list where email=? ";

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>");

for (int i = 0; i < arr.size(); i++) {%>

<% 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("</td>"); %>

<%out.println("</tr>"); %>

<% } %>

<% out.println("<br>");%>

<% out.println("</table>");%>

</b></h1>

</body>

</html>

Loginpage.jsp

<%@page contentType="text/html" language="java" import="java.util.*,java.io.*,java.sql.*"


%>

<%

try {

String mai = request.getParameter("mail");


63
IT3401-WEB
String pass = request.getParameter("pswd");

Class.forName("com.mysql.jdbc.Driver");

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/asd",


"root", "");

String sql = "select * from user where email=? and pass=?";

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 {

out.println("Please Register YourSelf By Clicking Here"); %>

<html>

<body>

<h1>

<a href = "http://localhost:8080/book_bank/register.html" > Register </a>

</h1>

</body>

</html>

<%}

} catch (Exception e)

{ out.println(e);

64
IT3401-WEB
%>

Register.jsp

<%@page contentType="java" import="java.sql.*,java.io.*,java.util.*"


pageEncoding="UTF-8"%>

<%

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","");

String sql="insert into user (name,email,pass) values (?,?,?)";

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

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

<!DOCTYPE html>

<html>

<head>

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

<title>JSP Page</title>

</head>

<body>

<h1>requst</h1>

</body>

</html>

Returnform.jsp

<%@page import="java.net.ConnectException"%>

<%@page contentType="text/html" language="java" import="java.io.*,java.sql.*,java.util.*"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

66
IT3401-WEB
<html>

<head>

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

<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","");

String sql="delete from order_list where book=? and email=?";

PreparedStatement ps=conn.prepareStatement(sql);

ps.setString(1, book );

ps.setString(2, email);

ps.executeUpdate();

String getQua="select quantity from book where name=?";

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>

<% out.println(email); %>

<h1><b>Book Returned</b></h1>

</body>

</html>

Newcss.css

#wpd1a

text-align: center;

font-size: 50px;

#lg1hd

68
IT3401-WEB
{

font-size: 50px; text-align: center;

#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{

border: 1px solid black;

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

Return book by clicking

72
IT3401-WEB
return

On successful return

RESULT:

Thus,the above program was executed and verified

73
IT3401-WEB
ExNo:9

Date: CREATING THREE TIER APPLICATIONS USING


SERVLET FOR STUDENT MARK LIST

AIM:

To write programs in Java to create three-tier applications using servlets for


conducting on-line examination for displaying student mark list.

PROCEDURE:

HTML

Step 1: Write a html file which contains a form that is directed to a servlet

Step 2: Write various questions and choices

Step 3: Include two buttons reset and click

SERVLET

Step 1: Import all necessary packages

Step 2: Define a class that extends servlet

Step 3: In the doPost() method, do the following:

i) Set the content type of the response to "text/html"


ii) Create a writer to the response
iii) Get a paratmeter from the request
iv) If its value is equal to right answer then add 5 to mark variable
v) Similarly repeat step for all parameters
vi) Display the result in an html format using the writer
PROGRAM:
ExamClient.html

<html>

<head><title>Online Exam Client</title></head>

<body>

<h2>ONLINE EXAMINATION</h2>

74
IT3401-WEB
<h3>Answer the following questions (5 marks for each correct answer)</h3>

<form name="examForm" method="post"


action="http://localhost:8080/examples/servlets/servlet/OnlineExam.java">

<input type="radio" name="ans1" value="Operating System">Operating System

<input type="radio" name="ans1" value="Application Software">Application Software

<input type="radio" name="ans1" value="CD Drive">CD Drive

<input type="radio" name="ans1" value="Microsoft word">Microsoft word

<br/><br/>

<input type="radio" name="ans2" value="Private Computer">Private Computer

<input type="radio" name="ans2" value="Professional Computer">Professional Computer

<input type="radio" name="ans2" value="Personal Computer">Personal Computer

<input type="radio" name="ans2" value="Personal Calculator">Personal Calculator

<br/><br/>

<input type="radio" name="ans3" value="Dennis Ritchie">Dennis Ritchie

<input type="radio" name="ans3" value="Stroustrup">Stroustrup

<input type="radio" name="ans3" value="David Ritchie">David Ritchie

<input type="radio" name="ans3" value="Charles Babbage">Charles Babbage

<br/><br/>

<input type="submit" value="Check Your Result"/>

</form>

</body>

</html>

OnlineExam.java

import java.io.*;

import java.util.*;

75
IT3401-WEB
import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;

public class OnlineExam extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

static final String DB_URL="jdbc:mysql://localhost:3306/Test","root","";

response.setContentType("text/html");

PrintWriter out = response.getWriter();

try {

Class.forName("com.mysql.jdbc.Driver");

Connection conn = DriverManager.getConnection(DB_URL);

Statement stmt = conn.createStatement();

String sql;

sql = "SELECT * from Exam";

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())

//Retrieve by column name

76
IT3401-WEB
String one1 =rs.getString("one");

String two2 =rs.getString("two");

String three3 =rs.getString("three");

if(one1.equals(first))

out.println("1. Answer is: OperatingSystems"+"<br>"+" Answer is correct"+"<br>");

else

out.println("1. Answer is: OperatingSystems"+"<br>"+" Answer is wrong"+"<br>");

if(two2.equals(second))

out.println("2. Answer is Personal Computer"+"<br>"+"Answer is correct"+"<br>");

else

out.println("2. Answer is: Personal Computer"+"<br>"+" Answer is wrong"+"<br>");

if(three3.equals(third))

out.println("3. Answer is Dennis Ritchie"+"<br>"+"Answer is correct"+"<br>");

else

out.println("3.. Answer is: Dennis Ritchie"+"<br>"+" Answer is wrong"+"<br>");

out.println("</body></html>");

rs.close();

stmt.close();

conn.close();

catch(SQLException se)

{ se.printStackTrace();

77
IT3401-WEB
catch(Exception e) {

//Handle errors for Class.forName

e.printStackTrace();

OUTPUT:

RESULT:Thus,the above program was executed and verified.

78
IT3401-WEB

You might also like