0% found this document useful (0 votes)
44 views62 pages

WT-lab-Manual MASTER MANUAL

The document is a lab manual for the WEB TECHNOLOGIES Lab at CMR Engineering College for the CSE (AI & ML) department, applicable to the 2023-24 academic year. It outlines the vision and mission of the department, program outcomes, educational outcomes, and specific lab instructions, including a list of experiments to be conducted. The manual emphasizes the importance of technical education and hands-on experience in the field of Artificial Intelligence and Machine Learning.

Uploaded by

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

WT-lab-Manual MASTER MANUAL

The document is a lab manual for the WEB TECHNOLOGIES Lab at CMR Engineering College for the CSE (AI & ML) department, applicable to the 2023-24 academic year. It outlines the vision and mission of the department, program outcomes, educational outcomes, and specific lab instructions, including a list of experiments to be conducted. The manual emphasizes the importance of technical education and hands-on experience in the field of Artificial Intelligence and Machine Learning.

Uploaded by

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

CMR Engineering College CSE(AI &ML)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING (AI & ML)


Applicable From 2020-21 Admitted Batch

LAB MANUAL (MASTER)

Name of the Lab : WEB TECHNOLOGIES Lab

Branch : Computer Science &Engineering-

Year : IV Year I semester

Regulation : R20

A.Y. : 2023-24

WT LAB 1
CMR Engineering College CSE(AI &ML)

CSE (AI & ML) Department Vision & Mission


Vision:
 To produce admirable and competent graduates and experts in CSE Artificial Intelligence &
Machine Learning through the quality technical education, innovations and research to improve
the life style and need of the society.

Mission:
 M1: To impart value based technical education in CSE specific to AI & ML through innovative
teaching and learning methods.
 M2: To produce outstanding professionals by imparting quality training, hands-on-experience and
value based education.
 M3: To produce competent graduates suitable for industries and organizations at global level
including research and development for Social responsibility.

CSE (AI &ML) Proposed Program Outcomes (POs):


WT LAB 2
CMR Engineering College CSE(AI &ML)

Engineering Graduates will be able to satisfy these NBA graduate attributes:

1. Engineering knowledge: An ability to apply knowledge of computing, mathematics, science and


engineering fundamentals appropriate to the discipline.
2. Problem analysis: An ability to analyze a problem, and identify and formulate the computing
requirements appropriate to its solution.
3. Design/development of solutions: An ability to design, implement, and evaluate a computer-based
system, process, component, or program to meet desired needs with appropriate consideration for
public health and safety, cultural, societal and environmental considerations.
4. Conduct investigations of complex problems: An ability to design and conduct experiments, as
well as to analyze and interpret data.
5. Modern tool usage: An ability to use current techniques, skills, and modern tools necessary for
computing practice.
6. The engineer and society: An ability to analyze the local and global impact of computing on
individuals, organizations, and society.
7. Environment and sustainability: Knowledge of contemporary issues.
8. Ethics: An understanding of professional, ethical, legal, security and social issues and responsibilities.
9. Individual and team work: An ability to function effectively individually and on teams,
including diverse and multidisciplinary, to accomplish a common goal.
10. Communication: An ability to communicate effectively with a range of audiences.
11. Project management and finance: An understanding of engineering and management principles and
apply these to one’s own work, as a member and leader in a team, to manage projects.
12. Life-long learning: Recognition of the need for and an ability to
Engage in continuing professional development.

CSE (AI & ML) Program Educational Outcomes (PEOs)

WT LAB 3
CMR Engineering College CSE(AI &ML)

PEO1. Excel in professional career and higher education by acquiring knowledge


of mathematical computing and engineering principles.
PEO2. To provide intellectual environment to successfully pursue higher education specific to AI & ML.
PEO3. To impart knowledge in cutting edge Artificial Intelligence technologies in par with
industrial standards.
PEO4. To create an atmosphere to explore research areas and produce outstanding contribution
in various areas of Artificial Intelligence and Machine Learning

CSE (AI & ML) Proposed Program specific Outcome (PSOs)


1. Professional Skills and Foundations of Software development: Ability to use knowledge in
emerging technologies in identifying research gaps and provide solutions with innovative ideas.
2. Applications of Computing and Research Ability: Ability to analyze the problem to provide
optimal solution by fundamental knowledge and skills in Professional, Engineering Sciences.

LAB CODE
WT LAB 4
CMR Engineering College CSE(AI &ML)

 Students should report to the concerned lab as per the time table.

 Students who turn up late to the labs will in no case be permitted to do the program schedule for the day.

 After completion of the program, certification of the concerned staff in-charge in the observation book is necessary.

 Student should bring a notebook of 100 pages and should enter the readings /observations into the notebook while
performing the experiment.

 The record of observations along with the detailed experimental procedure of the experiment in the immediate

last session should be submitted and certified staff member in-charge.

 The group-wise division made in the beginning should be adhered to and no mix up of students among different
groups will be permitted.

 When the experiment is completed, should disconnect the setup made by them, and should return all the
components/instruments taken for the purpose.

 Any damage of the equipment or burn-out components will be viewed seriously either by putting penalty or by dismissing
the total group of students from the lab for the semester/year.

 Students should be present in the labs for total scheduled duration.

 Students are required to prepare thoroughly to perform the experiment before coming to laboratory.

WT LAB 5
CMR Engineering College CSE(AI &ML)

B.TECH IV Year I Sem L T P C


0 0 3 1.5
AI703PC: WEB TECHNOLOGIES LAB

SI.NO List Of Experiments Page No


1 Write a PHP script to print prime numbers between 1-50. 7
2 PHP script to 7
a. Find the length of a string.
b. Count no of words in a string.
c. Reverse a string.
d. Search for a specific string.

3 Write a PHP script to merge two arrays and sort them 9


as numbers, in descending order.

4 Write a PHP script that reads data from one file and write into 9
another file.
5 Develop static pages (using Only HTML) of an online 13
book store.
6 The pages should resemble:www.amazon.com. The 13
website should consist the following pages.
a) Home page
b) Registration and user Login
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation
7 Validate the Registration, user login, user profile and payment 24
by credit card pages using JavaScript.
8 Create and save an XML document on the server, which 36
contains 10 users information. Write a program, which
takes User Id as an input and returns the user details by
taking the user information from the XML document.

9 install TOMCAT web server. Convert the static web pages of 39


assignments 2 into dynamic web pages using servlets and
cookies. Hint: Users information (user id, password, credit
card
number) would be stored in web.xml. Each user should have
a separate Shopping Cart.
10 Redo the previous task using JSP by converting the static web 53
pages of assignments 2 into dynamic web pages. Create a
database with user information and books information. The
books catalogue should be dynamically loaded from the
database. Follow the MVC architecture while doing the
website.
WT LAB 6
CMR Engineering College CSE(AI &ML)

1. Write a PHP script to print prime numbers between 1-50.


<?php
$number = 2 ;
while ($number <100 )
{
$div_count=0;
for ( $i=1;$i<=$number;$i++)
{
if (($number%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $number." , ";
}
$number=$number+1;
}
?>
OUTPUT:2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47

2. PHP script to
a. Find the length of a string.

<!DOCTYPE html>
<html>
<body>

<?php
echo strlen("Hello world!");
?>

</body>
</html>
OUTPUT:
12
b. Count no of words in a string.
<!DOCTYPE html>
<html>
<body>

<?php
echo str_word_count("Hello world!");
?>

WT LAB 7
CMR Engineering College CSE(AI &ML)

</body>
</html>
OUTPUT:
c. Reverse a string.
<!DOCTYPE html>
<html>
<body>

<?php
echo strrev("Hello world!");
?>

</body>
</html>
OUTPUT:
!dlrowolleH
d. Search for a specific string.
<!DOCTYPE html>
<html>
<body>

<?php
echo strpos("Hello world!", "world");
?>

</body>
</html>
OUTPUT:
6
<!DOCTYPE html>
<html>
<body>
<?php
echo str_replace("world", "Dolly", "Hello world!");
?>
OUTPUT:
Hello Dolly!
</body>
</html>

WT LAB 8
CMR Engineering College CSE(AI &ML)

3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.
<?php
$a1=array(1,3,15,7,5);
$a2=array(4,3,20,1,6);
$num=array_merge($a1,$a2);
array_multisort($num,SORT_DESC,SORT_NUMERIC);
print_r($num);
?>
Array ( [0] => 20 [1] => 15 [2] => 7 [3] => 6 [4] => 5 [5] => 4 [6] => 3 [7] => 3 [8] => 1 [9] => 1 )
4. Write a PHP script that reads data from one file and write into another file.

<?php
if(isset($_POST['save']))

$f=$_POST['file'];

$ext=$_POST['ext'];

$data=$_POST['data'];

$file=$f.$ext;

if(file_exists($file))

echo "<font color='red'>file already exists</font>";

else

$fo = fopen($file,"w");

fwrite($fo,$data);

echo "your data is saved";

WT LAB 9
CMR Engineering College CSE(AI &ML)

?>

<form method="post">

enter your file<input type="text" name="file"/><br/>

choose your extension<select name="ext">


<option value="">choose urexten</option>
<option>.txt</option>
<option>.docs</option>
<option>.pdf</option>
</select><br/>

Enter your contents<textarea rows="10" cols="30" name="data">

<?php echo @$contents ; ?>

</textarea><br/>

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

</form>

<?php

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

WT LAB 10
CMR Engineering College CSE(AI &ML)

$f=$_POST['file'];

$ext=$_POST['ext'];

$file=$f.$ext;

if(file_exists($file))

$fo = fopen($file,"r");

$contents = fread($fo,filesize($file));

else

echo "<font color='red'>file doesn't exists</font>";

?>

<form method="post">

enter your file<input type="text" name="file"/><br/>

choose your extension<select name="ext">


<option value="">choose urexten</option>
<option>.txt</option>
<option>.docs</option>
<option>.pdf</option>
</select><br/>

Enter your contents<textarea rows="10" cols="30" name="data">

<?php echo @$contents ; ?>

WT LAB 11
CMR Engineering College CSE(AI &ML)

</textarea><br/>

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

</form>

WT LAB 12
CMR Engineering College CSE(AI &ML)

5. &6. Develop static pages (using Only HTML) of an online book store. The pages should
resemble: www.amazon.com. The website should consist the following pages.
a) Home page
b) Registration and user Login
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation
Home page

Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post" action="login.html" target=_blank >
<h4>for books</h4><input type="submit" value="click here">
</form>
</center>
</body>
</html>

Registration and user Login

Login.html:
<html>
<head>
<title>
login</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>

WT LAB 13
CMR Engineering College CSE(AI &ML)

<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="reg.html" >
<input type="submit" value="register" >
&nbsp;&nbsp;
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>

Registration page

reg.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>

WT LAB 14
<tr>
<td><h4>male &nbsp;&nbsp;
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset" value="reset"></td>
</tr>
</form>
</body>
</html>

Userprofile

userprofile.html
<html>
<head>
<title>
userprofile</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON Online Book Store </h1></strong></center>
Edit your profile here...
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>Edit user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>Edit password</td>
<td><input type="password"></td>
</tr>

WT LAB 15
<tr>
<option >
<td><h4>male &nbsp;&nbsp;
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Edit Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
</tr>
</form>
</body>
</html>

Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>

WT LAB 16
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql</td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>

Shopping cart

Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>

WT LAB 17
<select >
<optgroup label="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" id="q">
</td></tr>
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
<body>
</html>

Payment by credit card

Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="cyan">
<center><h1>Payment By Credit Card</h1></center>
<form method=post action="ordrconform.html">
<br><br><br><br><br>
<table align="center">
<tr>
<td>
<h4>Total Amount</h4></td>

WT LAB 18
<td><input type="text">
</td>
</tr>
<tr>
<td><h4>Credit Card Number</td>
<td><input type="text"></td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" value=OK>
</td>
</tr>
</table>
</form></body>
</html>

Order Conformation

Ordrconform:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>

WT LAB 19
output:

WT LAB 20
WT LAB 21
WT LAB 22
WT LAB 23
7. Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
Homepage:

Main.html:

<html>

<frameset rows="25%,*">
<frame src="top.html" name="top" scrolling ="no" frameborder ="0">
<frameset cols="25%,75%">
<frame src="left.html" name="left" scrolling ="no" frameborder ="0">
<frame src="right.html" name="right" scrolling ="auto" frameborder ="0">
</frameset>
</frameset>
</html>

Top.html:

<html>
<body bgcolor="pink">
<br><br>
<marquee><h1
align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>

Right.html:

<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press
login if you are having id otherwise press
registration.
</p></b></h2>
</body></html>

Left.html:

WT LAB 24
<html>
<body bgcolor="pink">
<h3>
<ul>
<li><a href="login.html"
target="right"><font color="black">
LOGIN</font></a></li><br><br>
<li><a href="profile.html"
target="right"><font color="black"> USER
PROFILE</font></a></li><br><br>
<li><a href="catalog.html"
target="right"><font color="black"> BOOKS
CATALOG</font></a></li><br><br>
<li><a href="scart.html"
target="right"><font color="black">
SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font
color="black">
PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Registration and user Login

Login.html:

<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value=="
"||
document.myform.pwd.value==
"")
{
alert("LoginId and Password must be
filled") flag=0;
}
if(flag==1)
{

WT LAB 25
alert("VALID INPUT");
window.open("catalog.html","right");
}
else
{
alert("INVALID INPUT");
//document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password"
name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</div>

</form>
</body>
</html>
User profilepage

Profile.html:

<html>
<body bgcolor="pink"><br><br>
<script
type="text/javasc
ript"> function
validate()
{
var flag=1;
if(document.myform.name.value
==""||
document.myform.add
r.value==""||
document.myform.phn
o.value==""||
document.myform.id.v
alue==""||
document.myform.pw

WT LAB 26
d.value=="")
{
alert("Enter all the details");
flag=0;
}
var str=document.myform.phno.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
if(!(str.
length
==10))
flag=0
;
}
var str1=document.myform.id.value;
var x1=new RegExp("^[A-Z][a-
zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid UserID");
}
var
str1=document.myform.pwd.valu
e; var x1=new RegExp("^[A- Z]
[a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid password");
}
if(f
lag
==
1)
{
alert("VALID INPUT");
window.self.location.href="login.html";
}

WT LAB 27
else
{
alert("INVALIDINPUT");
document.myform.focus();
<br><br>
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input
type="type" name="addr"><br> CONTACT NUMBER:<input
type="text"name="phno"><br> LOGINID :<input
type="text"name="id"><br>
PASSWORD :<input type="password"name="pwd"></pre><br><br>
</div>

<div align="center">
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</form></body></html>

Bookscatalog:

Scart.html:

<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript
"> function
validate()
{
var flag=1;
if(document.myform.title.val
ue=="")
{
flag=0;
}

str=document.myform.title.value;

if(str=="c"||str=="C")

WT LAB 28
{
document.myform.t1.value="C";
document.myform.t2.value=444;
}
else if(str=="jsp"||str=="JSP")

else{
document.myform.t1.value="JSP"; document.myform.t2.value=555;
}

{
flag=0;
}

Shoppingcart:

Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript
"> function
validate()
{
var flag=1;
if(document.myform.id.value
==""||
document.myform.title.valu
e==""||
document.myform.no.valu
e==""||
document.myform.cost.val
ue=="")
{
flag=0;
}

str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{

WT LAB 29
flag=0;
}
if(flag==1)
{

alert("VALID INPUT");

else
}

{
alert("INVALIDINPUT");
document.myform.focus();
}
</script>
<form name="myform" action="scart.html" target="right">
<div align="center"><pre>
LOGINID :<input type="text"
name="id"><br> TITLE :<input
type="text" name="title"><br>NO.OFBOOKS
:<input type="text"name="no"><br>
COSTOFBOOK :<input type="text"name="cost"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</form>
</body>
</html>

Payment by creditcard

WT LAB 30
Payment.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""|| document.myform.pwd.value==""||
document.myform.amount.value==""|| document.myform.num.value=="")
{
flag=0;
}
var str=document.myform.amount.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="order.html";
}
else
{
alert("INVALIDINPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input
type="text"name="amount"><br>
CREDITCARDNUMBER :<input type="PASSWORD"name="num"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</form>
</body>

WT LAB 31
</html>

Order ConformationOrder.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
OUTPUT:

Main.html

Login.html:

WT LAB 32
Catalog.html:

WT LAB 33
Scart.html:

WT LAB 34
Payment.html:

Order.html

WT LAB 35
8. Create and save an XML document on the server, which contains 10 users information.
Write a program, which takes User Id as an input and returns the user details by taking the
user information from the XML document.
<employees>
<employee id="111">
<firstName>Chandrika</firstName>
<lastName>Gupta</lastName>
<location>India</location>
</employee>
<employee id="222">
<firstName>Srinivas</firstName>
<lastName>Reddy</lastName>
<location>Russia</location>
</employee>
<employee id="333">
<firstName>Anupama</firstName>
<lastName>P</lastName>
<location>USA</location>
</employee>

<employee id="444">
<firstName>Lokesh</firstName>
<lastName>Gupta</lastName>
<location>India</location>
</employee>
<employee id="555">
<firstName>Vishnu</firstName>
<lastName>Gussin</lastName>
<location>Russia</location>
</employee>
<employee id="666">
<firstName>Veeru</firstName>
<lastName>Feezor</lastName>
<location>USA</location>

WT LAB 36
</employee>
<employee id="777">
<firstName>Pavan</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>

<employee id="888">
<firstName>Narayana</firstName>
<lastName>Gussin</lastName>
<location>Russia</location>
</employee>
<employee id="999">
<firstName>David</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>
<employee id="1000">
<firstName>Sunder</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>
</employees>
ReadXML.java:

import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
import java.util.Scanner;
publicclassReadXML {
publicstaticvoidmain(String a[]) throws
Exception{ DocumentBuilderFactory factory
=
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

//Build Document
Document document = builder.parse(new
File("C:\\Users\\Narayana\\Desktop\\employees.xml"));
//Normalize the XML Structure; It's just too
important !!
document.getDocumentElement().normalize();

WT LAB 37
//Here comes the root node
Element root = document.getDocumentElement();

//Get all employees


NodeListnList = document.getElementsByTagName("employee");
System.out.println("enter employee id:");
Scanner s=new Scanner(System.in);
String id=s.next();
for (int temp = 0; temp <nList.getLength(); temp++)
{
Node node = nList.item(temp);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) node;
if(eElement.getAttribute("id").equals(id)){
System.out.println("First Name : "+
eElement.getElementsByTagName("firstName").item(0).getTextContent());
System.out.println("Last Name:" +
eElement.getElementsByTagName("lastName").item(0).getTextContent());
System.out.println("Location:" +
eElement.getElementsByTagName("location").item(0).getTextContent());
}
}
}
}
}

OUTPUT:-

Enter Employee Id: 222

WT LAB 38
9. Install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic
web pages using servlets and cookies. Hint: Users information (user id, password, credit card
number) would be stored in web.xml. Each user should have a separate Shopping Cart.
PROCEDURE:

First install the tomcat into the system.


Then make a subdirectly(eg., tr) in the \tomcat\webapps.
Under tr create WEB-INF directory and also place the html files in this tr
directory only. Next under WEB-INF create two subclasses lib,classes and
web.xml
Next place all the class files under the classes and jar files(servlet-api.jar,classes12.jar etc…)
under lib subdirectories.
After this start tomcat by giving the following command at
the instll_dir>tomcat>bin Catalina.bat run
At the I.E(web browser) give the url as http;//localhost:8080//tr/htmlfile or servlet url
pattern Portno 8080 is assigned for the tomcat.

Web.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Servlet 2.4 Examples</display-name>
<description>
Servlet 2.4 Examples.
</description>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>

WT LAB 39
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-p</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>attern>order<
/url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>catalog</url-pattern>
</servlet-mapping> 26
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>reg</url-pattern>
</servlet-mapping>
</web-app>
Main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink">
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br /><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book
storage. Press LOGIN if you are
having id otherwise press
REGISTRATION
</b></pre></h2>
<br /><br/><pre>
<div align="center"><a
href="/tr/login.html">LOGIN</a><a href="/tr/reg.html">
REGISTRATION</a></div></pre>
</body>
</html>

Login.html

WT LAB 40
<html>
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"
value="clear" />
</div>
</form>
</body>
</html>
Reg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br />
<form name="myform" method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br/>
ADDRESS :<input type="text" name="addr"
/><br /> CONTACTNUMBER :<input type="text"
name="phno" /><br /> LOGINID :<input type="text"
name="id"
/><br/>
PASSWORD :<input type="password" name="pwd" /></pre><br /><br/>
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"
value="clear" />
</div>
</form>
</body>
</html>
Profile.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/profile">

WT LAB 41
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"
value="clear" />
</div></form></body></html>
Catalog.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form method="post" action="/tr/catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear"name="button2"/>
</div>
</form>
</body></html>
Order.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<body bgcolor="pink"><br /><br />


<form method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name"
/><br /> PASSWORD :<input type="password"
name="pwd" /> TITLE :<input type="text"
name="title"
/><br />NO.OFBOOKS :<input type="text" name="no"
/><br /> DATE :<input type="text" name="date"
/><br/>
CREDIT CARD NUMBER:<input type="password" name="cno" /><br /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"

WT LAB 42
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"
value="clear" name="button2"/>
</div>
</form>
</body>
</html>
Login.java 29
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{ PrintWriter
pw=resp.getWriter();
pw.println("<html><body bgcolor=\"pink\");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd"); try
{ Driver
d=neworacle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{

WT LAB 43
}
else
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to RETRY</a>");

pw.println("VALID LOGIN ID<br><br>");


pw.println("<h3><ul>");
pw.println("<li><ahref=\"profile.html\"><fontcolor=\"black\">USER PROFILE</font>
</a></li><br><br>");

pw.println("<li><ahref=\"catalog.html\"><fontcolor=\"black\">BOO
KS CATALOG</font></a></li><br><br>");
pw.println("<li><ahref=\"order.html\"><fontcolor=\"black\">OR
DER CONFIRMATION</font> </a></li><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
}
}
Reg.html 30
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
name=req.getParamenter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd"); int

WT LAB 44
no=Integer.parseInt(phno);
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
} }
if(flag==1)
{
pw.println("SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH NEW
ID<br><br>");
pw.println("<a href=\"/tr/reg.html\">press REGISTER to RETRY</a>");
}
else
{ Statement
stmt1=con.createStatement();
stmt1.executeUpdate("insertintologin
values("+names","+addr+","+no+","+id+","+pwd+")");
pw.println("YOUR DETAILS
AREENTERED<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
} }}
Catlog.java 31
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;

WT LAB 45
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
title=req.getParameter("title");
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
pw.println(",div align=\"center\">");
pw.println("TITLE
:"+rs.getString(1)+"<br>
"); pw.println("AUTHOR :"+rs.getString(2)+"<br>");
pw.println("VERSION :"+rs.getString(3)+"<br>");
pw.println("PUBLISHER
:"+rs.getString(4)+"<br>
"); pw.println("COST
:"+rs.getString(5)+"<br>
"); pw.println("</div");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID TITLE TRY AGAIN <br><br>");
pw.println("<a href=\"/tr/catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}

WT LAB 46
}
}
Profile.java
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
id=req.getParamenter("id");
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:ora
cle:thin:
@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login
where id="+id+"";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME
:"+rs.getString(1)+"<br>"
);
pw.println("ADDRESS:"+rs.getString(2)+"<br
>");
pw.println("PHONENO
:"+rs.getString(3)+"<br>"
); pw.println("</div>");
flag=1;
}
if(flag==0)
{

WT LAB 47
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order.java 33
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd");
String
title=req.getParameter("title");
String
count1=req.getParameter("no");
String
date=req.getParameter("date");
String
cno=req.getParameter("cno");
intcount=Integer.parseInt(count1);
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from

WT LAB 48
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int
flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");

}
else
{

Statement stmt2=con.createStatement();
String s="select cost from book where title="+title+""; ResultSet
rs1=stmt2.executeQuery(s);
int flag1=0; while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(
1));
amount=count*x; 34
pw.println("AMOUNT :"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insertintodetailsvalues('"+id+",'"+title
+"'+amount+'","'+cno+'")"'); pw.println("YOUR ORDER has
taken<br>");
}
if(flag1==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");

}
}
pw.println("</body></html>");
con.close();
}

WT LAB 49
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
35

WT LAB 50
36

WT LAB 51
37

WT LAB 52
10. Redo the previous task using JSP by converting the static web pages of assignments 2
into dynamic web pages. Create a database with user information and books information. The
books catalogue should be dynamically loaded from the database. Follow the MVC
architecture while doing the website.
PROCEDURE:

1) Create your own directory under tomcat/webapps (e.g.tr1)


2) Copy the html files intr1
3) Copy the jsp files also intotr1
4) Start tomcat give the
following command
Catalina.batrun
At install‐dir/bin
5) at I.E give url ashttp://localhost:8081/tr1/main.html

Main.html:

<html>
<body bgcolor=”pink”>
<br><br><br><br><br><br>
<h1 align=”center”>>U>ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align=”center”><PRE>
<b> Welcome to online book
storage. Press LOGIN if
you are having id
Otherwise press REGISTRATION
</b></PRE></h2>
<br><br><pre>
<div align=”center”><a
href=”/tr/login.html”>LOGIN</a>href=”/tr/log
in.html”>REGISTRATION</a></div></pre>
</body></html>

Login.html:

<html>
<body bgcolor=”pink”><br><br><br>
<form name="myform" method="post" action=/tr1/login.jsp">
<div align="center"><pre>
LOGIN ID :<input type="passwors"
name="pwd"></pre><br><br> PASSWORD : <input
type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">

WT LAB 53
</form>
</body></html>

Reg.html:

<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/reg.jsp">
<div align="center"><pre>
NAME :<input type="text"
name="name"><br> ADDRESS :<input
type="text"name="addr"><br>
CONTACT NUMBER :<input type="text"
name="phno"><br> LOGINID : <input
type="text"name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear">
</form>
</body>
</html>

Profile.html:

<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/profile.jsp">
<div align="center"><pre>
LOGINID : <input type="text"name="id"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear">
</form>
</body>
</html>

WT LAB 54
Catalog.html:

<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/catalog.jsp">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<inputtype="reset"value="clear"
name=”button2
”>
</form>
</body>
</html>
Order.html:

<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/order.jsp">
<div align="center"><pre>
LOGINID :<input type="text"
name="id"><br>PASSWORD :<input
type="password" name="pwd"><br> TITLE
:<input
type="text"name="title"><br>
NO. OF BOOKS :<input type="text"
name="no"><br> DATE : <input
type="text"name="date"><br>
CREDIT CARD NUMBER :<input type="password" name="cno"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear"name=”button2”>
</form>
</body>
</html>
Login.jsp: 41
%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%

out.println(“<html><body
bgcolor=\”pink\”>”); String

WT LAB 55
id=request.getParameter(“id”);
String
pwd=request.getParameter(“pwd”);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”selectid,password from login where id=”+id+” and
password=”+pwd+””; ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.nex
t())
{
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”);
out.println(“ <a href=\”/tr1/login.html\”>press LOGIN to RETRY</a>”);
}
else
{
out.println(“VALID LOGIN ID<br><br>”);
out.println(“<h3><ul>”);
out.println(“<li><ahref=\”profile.html\”><fontcolor=\”black\”>USER
PROFILE</font></a></li><br><br>”);

out.println(“<li><ahref=\”catalog.html\”><fontcolor=\”black\”>BOOKS
CATALOG</font></a></li><br><br>”);
out.println(“<li><ahref=\”order.html\”><fontcolor=\”black\”>ORDER
CONFIRMATION</font></a></li><
br><br>”); out.println(“</ul>”);
}
out.println(“<body></html>”);
%>
42
Reg.jsp:

%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body
bgcolor=\”pink\”>”); String
name=request.getParameter(“name”);
String
addr=request.getParameter(“addr”);

WT LAB 56
String
phno=request.getParameter(“phno”);
String id=request.getParameter(“id”);
String
pwd=request.getParameter(“pwd”);
int no=Integer.parseInt(phno);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement();
String sqlstmt=”select id from
login”;
ResultSetrs=stmt.executeQuery(sql
stmt); int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1)))
{
flag=1;
}
}
if(flag==1)
{
out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID <br><br>”);
out.println(“<a href=\”/tr1/reg.html\”>press REGISTER to RETRY</a>”);
}
else
{
Statement stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into login values
(“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”); out.println (“YOU DETAILS
ARE ENTERED <br><br>”);
out.println (“<a href =\”/tr1/login.html\”>press LOGIN to login</a>”);
}
out.println (“</body></html>”);
%>
Profile.jsp: 43
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter(“id”);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.regiserDriver(d);

WT LAB 57
Connection con=
DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”s
cott”,”tiger”); Statement stmt=con.createStatement ();
String sqlstmt=”select * from login where
id=”+id+””; ResultSetrs=stmt.executeQuery
(sqlstmt);
int
flag=0;
while(rs.next())
{
out.println (“<div align=\”center\”>”);
out.println(“NAME
:”+rs.getString(1)+”<b
r>”); out.println (“ADDRESS
:”+rs.getString(2)+”<br>”); out.println
(“PHONE NO :”+rs.getString(3)+”<br>”);
out.println (“</div>”);
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/profile.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>
Catalog.jsp:

<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
title=request.getParameter (“title”);
Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();
String sqlstmt=”select * from book where
title=”+title+””; ResultSetrs=stmt.executeQuery
(sqlstmt);
int
flag=0;
while(rs.nex
t())

WT LAB 58
{
out.println (“<div align=\”center\”>”);
out.println(“TITLE
:”+rs.getString(1)+”<br
>”); out.println (“AUTHOR
:”+rs.getString(2)+”<br>”); out.println
(“VERSION:”+rs.getString(3)+”<br>”);
out.println (“PUBLISHER :”
+rs.getString(4)+”<br>”); out.println
(“COST :”
+rs.getString(5)+”<br>”); out.println
(“</div>”);
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/catalog.html\”>press HERE to RETRY </a>”);
}

out.println (“</body></html>”);
%>

Order.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter (“id”);
String pwd=request.getParameter
(“pwd”); String
title=request.getParameter (“title”);
String count1=request.getParameter
(“no”); String
date=request.getParameter (“date”);
String cno=request.getParameter
(“cno”); int
count=Integer.parseInt(count1);
Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();
String sqlstmt=”select id, password
from login”;
ResultSetrs=stmt.executeQuery
(sqlstmt);

WT LAB 59
int
flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
els
e{
Statement stmt2=con.createStatement();
String s=”select cost from book where
title=”+title+””; ResultSet
rs1=stmt2.executeQuery(s);
int flag1=0;
{ while(rs1.nex
t())

flag1=1;
x=Integer.parseInt(rs1.getStri
ng(1)); amount=count*x;
out.println(“AMOUNT
:”+amount+”<br><br><br><br>”); Statement
} stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into details
(“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”); out.println
(“YOU ORDER HAS TAKEN<br>”);
if(flag1==0)
{

WT LAB 60
out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY
</a>”);
}
} out.println (“</body></html>”);%>

WT LAB
61
WT LAB
62

You might also like