0% found this document useful (0 votes)
21 views69 pages

Latest WT Lab Manual Prepared by MMR 2021

Uploaded by

rodexmanoj
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)
21 views69 pages

Latest WT Lab Manual Prepared by MMR 2021

Uploaded by

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

WEB TECHNOLOGIES LAB 2021

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

prime_numbers_1_to_50.php

<!DOCTYPE html>
<html>
<body>

<?php
for($num=2 ;$num<=50; $num++)
{
$count=0;
for ( $i=1; $i<=$num; $i++)
{
if (($num%$i)==0)
{
$count++;
}
}
if ($count<3)
{
echo $num.",&nbsp;&nbsp;";
}
}

?>

</body>
</html>

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 1
WEB TECHNOLOGIES LAB 2021
2. a) PHP Script to find the length of a string.

strlen.html
<html>
<head>
<title>length of the string</title>
</head>
<body>
<form method="get" action="strlen.php">
enter a string:
<input type="text" name="str">
<br>
<br>
<input type="submit" value="find the length of string">
</form>
</body>
</html>

strlen.php

<html>
<head>
<title>length of the string</title>
</head>
<body>
<?php
$str=$_REQUEST["str"];
echo "<h1> the length of the string is &nbsp;",strlen($str),"</h1>";
?>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 2
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 3
WEB TECHNOLOGIES LAB 2021
b) PHP Script to count no of words in a string.

str_word_count.html
<html>
<head>
<title>count no of words in a string</title>
</head>
<body>
<form method="get" action="str_word_count.php">
enter a string:
<input type="text" name="str">
<br>
<br>
<input type="submit" value="count no of words in a string">
</form>
</body>
</html>

str_word_count.php

<html>
<head>
<title>count no of words in a string</title>
</head>
<body>
<?php
$str=$_REQUEST["str"];
echo "<h1> the no of words in a string is &nbsp;",str_word_count($str),"</h1>";
?>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 4
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 5
WEB TECHNOLOGIES LAB 2021
c) PHP Script to reverse a string

strrev.html

<html>
<head>
<title>reverse a string</title>
</head>
<body>
<form method="get" action="strrev.php">
enter a string:
<input type="text" name="str">
<br>
<br>
<input type="submit" value="reverse a string">
</form>
</body>
</html>

strrev.php

<html>
<head>
<title>reverse a string</title>
</head>
<body>
<?php
$str=$_REQUEST["str"];
echo "<h1> the reverse of a given string is &nbsp;",strrev($str),"</h1>";
?>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 6
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 7
WEB TECHNOLOGIES LAB 2021
d) PHP Script to search for a specific string.

strpos.html

<html>
<head>
<title>search a string from a given string</title>
</head>
<body>
<form method="get" action="strpos.php">
enter given string:
<input type="text" name="str">
<br>
<br>
enter search string:
<input type="text" name="search">
<br>
<br>
<input type="submit" value="search">
</form>
</body>
</html>

strpos.php

<html>
<head>
<title>reverse a string</title>
</head>
<body>
<?php
$str=$_REQUEST["str"];
$search=$_REQUEST["search"];

if(strpos($str,$search))
{
echo "<h1> the word &nbsp;",$search,"&nbsp; is at position &nbsp;";
echo strpos($str,$search),"</h1>";
}
else

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 8
WEB TECHNOLOGIES LAB 2021
{
echo "<h1> the word &nbsp;",$search,"&nbsp; is not found</h1>";
}
?>
</body>
</html>

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 9
WEB TECHNOLOGIES LAB 2021
3. Write a PHP Script to merge two arrays and sort them as numbers, in descending order.
merge_rsort.php
<html>
<head><title>merge two arrays and sort them as numbers, in desending
order</title></head>
<body>
<?php
$arr1=array(10,20,99,0,-1);
echo "<b>array 1 values are</b>";
echo "<br>";
print_r($arr1);
echo "<br>";

$arr2=array(5,30,50,-2);
echo "<b>array 2 values are</b>";
echo "<br>";
print_r($arr2);
echo "<br>";

$merge=array_merge($arr1,$arr2);
echo "<b>merge of array1 and array2 values are</b>";
echo "<br>";
print_r($merge);
echo "<br>";

echo "<b>desending order values are</b>";


echo "<br>";
rsort($merge);
print_r($merge);
?>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 10
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 11
WEB TECHNOLOGIES LAB 2021
4. Write a PHP Script that reads data from one file and write into another file.
file.text

read_from_write_other_file.php

<html>
<head><title>reads data from one file and write into another file</title></head>
<body>
<h1> Reading from a file</h1>
the file to read is<a href="file.txt"> file.txt</a><br>
<?php
$handle=fopen("file.txt","r");
$copytxt="";
while(!feof($handle)){
$text=fgets($handle);
echo $text,"<br>";
$copytxt.=$text;
}
fclose($handle);
?>
<h1> Writing to a file</h1>
<?php
$handle=fopen("data.txt","w");
if(fwrite($handle,$copytxt)==FALSE){
echo "can not write data.txt.";
}
else{
echo "created data.txt.";
?>
the created file is<a href="data.txt"> data.txt</a><br>
Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 12
WEB TECHNOLOGIES LAB 2021
<?php
}
fclose($handle);
?>

</body>
</html>
Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 13
WEB TECHNOLOGIES LAB 2021
5. 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.html

<HTML>
<HEAD><TITLE>HomePage</TITLE></HEAD>

<FRAMESET ROWS="20%,80%" BORDER="0">


<FRAME SRC="header.html">

<FRAMESET COLS="20%,80%" border="0">


<FRAME SRC="course.html">

<FRAMESET ROWS="20%,80%" BORDER="0">


<FRAME SRC="menu.html">
<FRAME SRC="default.html" name="display">
</FRAMESET>

</FRAMESET>

</FRAMESET>
</BODY>
</HTML>

header.html

<HTML>
<HEAD>
<TITLE> Header HTML File </TITLE>

</HEAD>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 14
WEB TECHNOLOGIES LAB 2021
<BODY>
<table>
<tr>
<td>
<IMG SRC="./logo.gif" WIDTH="200" HEIGHT="100" BORDER="0"
align="left" ALT="Sree Chaitanya college">
</td>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<FONT SIZE="1000" COLOR="#FFCC00" align="left" valign="bottom">
Sree Chaitanya College of Engineering</FONT>
</td>
</table>
</BODY>
</HTML>

course.html
<HTML>
<HEAD>
<TITLE> Course File </TITLE>

</HEAD>

<BODY>
<br>
<br>
<br>
<br>
<table height="50%" width="30%" cellspacing="30">
<tr><td valign="middle" align="left">
<A HREF="./catalogue.html" target="display">CSE</A>
</td></tr>
<tr><td valign="middle" align="left">

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 15
WEB TECHNOLOGIES LAB 2021
<A HREF="./catalogue.html" target="display">ECE</A>
</td></tr>
<tr><td valign="middle" align="left">
<A HREF="./catalogue.html" target="display">EEE</A>
</td></tr>
<tr><td valign="middle" align="left">
<A HREF="./catalogue.html" target="display">CIVIL</A>
</td></tr>

</BODY>
</HTML>

menu.html

<HTML>
<HEAD>
<TITLE> Menu File </TITLE>

</HEAD>

<BODY>
<table width="100%" height="20%" cellspacing="10">
<tr>
<td>
<A HREF="./home.html" target="_top" valign="middle"
align="center">Home</A>
</td>
<td>
<A HREF="./loginpage.html" target="display" valign="middle"
align="center">User Login</A>
</td>
<td>
<A HREF="./registration.html" target="display" valign="middle"
align="center">Registration</A>
</td>
<td>
<A HREF="./catalogue.html" target="display" valign="middle"
align="center">Books Catalogue</A>
</td>
<td>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 16
WEB TECHNOLOGIES LAB 2021
<A HREF="./cartPage.html" target="display" valign="middle"
align="center">Shopping Cart</A>
</td>
</tr>
</table>
</BODY>
</HTML>

default.html

<HTML>
<HEAD>
<TITLE> Default file</TITLE>

</HEAD>

<BODY>
<CENTER><IMG SRC="./logo.gif" WIDTH="100" HEIGHT="100"
BORDER="0" ALT="Sree Chaitanya group of colleges"><BR>
<H1>Sree Chaitanya College of Engineering</H1><BR>
<H2>LMD-COLONY, KARIMNAGAR</H2><BR>
WEB TECHNOLOGIES LAB MANUAL

</CENTER>

</BODY>
</HTML>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 17
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 18
WEB TECHNOLOGIES LAB 2021
6. Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript

registration.html

<HTML>
<HEAD>
<TITLE> Registration </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validating() {
var name =
document.forms["register"]["user"];
var phone =
document.forms["register"]["phone"];
var password =
document.forms["register"]["pwd"];
var cpassword =
document.forms["register"]["cpwd"];
var email =
document.forms["register"]["emailid"];
var address =
document.forms["register"]["address"];
var date =
document.forms["register"]["date"];
var month =
document.forms["register"]["month"];
var year =
document.forms["register"]["year"];

if (name.value == "") {
window.alert("Please enter your name.");
name.focus();
return false;
}

if(password.value == "") {
window.alert("Please enter your Password");

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 19
WEB TECHNOLOGIES LAB 2021
password.focus();
return false;
}
if((password.value).length<6)
{
window.alert("Password must be at least 6 char
long");
password.focus();
return false;
}

if (cpassword.value == "") {
window.alert("Please enter your cpassword");
cpassword.focus();
return false;
}
if (cpassword.value != password.value )
{
window.alert("cpassword is not same as
password");
cpassword.focus();
return false;
}
if (email.value == "") {
window.alert("Please enter your email");
email.focus();
return false;
}
var x=document.register.emailid.value;
var atposition=x.indexOf("@");
var dotposition=x.lastIndexOf(".");
if (atposition<1 || dotposition<atposition+2 ||
dotposition+2>=x.length){
alert("Please enter a valid e-mail address \n atpostion:"+atposition+"\n
dotposition:"+dotposition);
return false;
}
if (phone.value == "") {
window.alert("Please enter your telephone number.");
phone.focus();

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 20
WEB TECHNOLOGIES LAB 2021
return false;
}
if((phone.value).length<10)
{
window.alert("Phone must be at least 10
digits");
phone.focus();
return false;
}

if (date.selectedIndex < 1) {
alert("Please enter your date in DOB.");
date.focus();
return false;
}
if (month.selectedIndex < 1) {
alert("Please enter your month in DOB.");
month.focus();
return false;
}
if (year.selectedIndex < 1) {
alert("Please enter your year in DOB.");
year.focus();
return false;
}

return true;
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<CENTER>
<FORM name="register" onsubmit="return validating()"><table>
<caption align=top><FONT SIZE="6" COLOR="#3300FF">Registration
Form</FONT></caption>
<tr><td align=right><LABEL><B><I>Enter your Name :</I></B></LABEL></td>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 21
WEB TECHNOLOGIES LAB 2021
<td><INPUT TYPE="TEXT" NAME="user" size="13"
maxlength="12"></td></tr>
<tr><td align=right><LABEL><B><I>Enter Password :</I></B></LABEL></td>
<td>
<INPUT TYPE="PASSWORD" NAME="pwd" size="13"
maxlength="12">
</td></tr>
<tr><td align=right><LABEL><B><I>Confirm
Password:</I></B></LABEL></td>
<td>
<INPUT TYPE="PASSWORD" NAME="cpwd" size="13"
maxlength="12">
</td></tr>
<tr><td align=right><LABEL><B><I>Email Id:</I></B></LABEL></td>
<td>
<INPUT TYPE="TEXT" NAME="emailid" size="19"
maxlength="20">
</td></tr>
<tr><td align=right><LABEL><B><I>Phone Number:</I></B></LABEL></td>
<td>
<INPUT TYPE="TEXT" NAME="phone" size="10"
maxlength="10">
</td></tr>
<tr><td align=right><LABEL><B><I>Date of birth :</I></B></LABEL></td>
<td><select name="date">
<option value="0">day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 22
WEB TECHNOLOGIES LAB 2021
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="11">21</option>
<option value="12">22</option>
<option value="13">23</option>
<option value="14">24</option>
<option value="15">25</option>
<option value="16">26</option>
<option value="17">27</option>
<option value="18">28</option>
<option value="19">29</option>
<option value="20">30</option>
<option value="20">31</option>
</select>
<select name="month">
<option value="0">month</option>
<option value="JAN">JAN</option>
<option value="FEB">FEB</option>
<option value="MAR">MAR</option>
<option value="APR">APR</option>
<option value="MAY">MAY</option>
<option value="JUN">JUN</option>
<option value="JUL">JUL</option>
<option value="AUG">AUG</option>
<option value="SEP">SEP</option>
<option value="OCT">OCT</option>
<option value="NOV">NOV</option>
<option value="DEC">DEC</option>
</select>
<select name="year">
<option value="0">year</option>
<option value="1971">1971</option>
<option value="1972">1972</option>
<option value="1973">1973</option>
<option value="1974">1974</option>
<option value="1975">1975</option>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 23
WEB TECHNOLOGIES LAB 2021
<option value="1976">1976</option>
<option value="1977">1977</option>
<option value="1978">1978</option>
<option value="1979">1979</option>
<option value="1980">1980</option>
<option value="1981">1981</option>
<option value="1982">1982</option>
<option value="1983">1983</option>
<option value="1984">1984</option>
<option value="1985">1985</option>
<option value="1986">1986</option>
<option value="1987">1987</option>
<option value="1988">1988</option>
<option value="1989">1989</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
</select></td></tr>
<tr><td align=right><LABEL><B><I>Gender :</I></B></LABEL></td>
<td>
<Input type="Radio" name="R1" value="Male" checked >Male

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 24
WEB TECHNOLOGIES LAB 2021
<Input type="Radio" name="R1" value="Female" checked >Female
</td></tr>
<tr><td align=right><LABEL><B><I>Language :</I></B></LABEL></td>
<td>
<Input type="checkbox" name="english" value="english" >English
<Input type="checkbox" name="telugu" value="telugu" >Telugu
<Input type="checkbox" name="hindi" value="hindi" >Hindi
<Input type="checkbox" name="tamil" value="tamil" >Tamil
</td></tr>
<tr><td align=right><LABEL><B><I>Country :</I></B></LABEL></td>
<td><select name="country">
<option selected>Select Country</option>
<option value="ind">India</option>
<option value="usa">United States of
America</option>
<option value="eng">England</option>
<option value="aus">Australia</option>
<option value="ger">Germany</option>
<option value="pol">Poland</option>
</select></td></tr>
<tr><td align=right><LABEL><B><I>Address :</I></B></LABEL></td>
<td><TEXTAREA NAME="address" ROWS="5" COLS="20">
</TEXTAREA></td></tr>
<tr><td align=center>
<Input type="submit" name="registration" value="submit" size=10> </td>
<td align=center><input type="reset" size=10></td></tr>
</table>
</form></CENTER>
</BODY>
</HTML>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 25
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 26
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 27
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 28
WEB TECHNOLOGIES LAB 2021
loginpage.html

<HTML>
<HEAD>
<TITLE> Login File</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function loginForm( )
{
if(document.getElementById('uid').value.length==0)
alert("UserId can't be blank")
else if(document.getElementById('pwd').value.length==0)
alert("Password can't be blank")
else
{
alert("successfully logged in")
window.open("Welcome.html")
}
}
//-->
</SCRIPT>

</HEAD>

<BODY>
<CENTER>
<FORM METHOD=POST ACTION="" name="login">
<TABLE>
<TR>
<TD align="right"><FONT SIZE="6" COLOR="#6600FF">Login
:</FONT></TD>
<TD align="left"><INPUT TYPE="text" NAME="login" size="15"
id="uid"></TD>
</TR>
<TR>
<TD align="right"><FONT SIZE="6"
COLOR="#6600FF">Password:</FONT></TD>
<TD align="left"><INPUT TYPE="password" NAME="pwd" size="15"
id="pwd"></TD>
</TR>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 29
WEB TECHNOLOGIES LAB 2021
<TR>
<TD align="right"><INPUT TYPE="submit" name="submit"
value="submit" onclick="loginForm( )"></TD>
<TD align="left"><INPUT TYPE="reset" name="reset"
value="reset"></TD>
</TR>
</TABLE>
</FORM>

</CENTER>

</BODY>
</HTML>

welcome.html

<HTML>
<HEAD>
<TITLE> Welcome</TITLE>

</HEAD>

<BODY>
<H1>Welcome to Sree Chaitanya College of Engineering</H1>
</BODY>
</HTML>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 30
WEB TECHNOLOGIES LAB 2021
Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 31
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 32
WEB TECHNOLOGIES LAB 2021
payment-validation.js

function cardnumber(inputtxt)
{
var cardno = /^(?:3[47][0-9]{13})$/;
if(inputtxt.value.match(cardno))
{
return true;
}
else
{
alert("Not a valid Amercican Express credit card number!");
return false;
}
}

payment.html

<html>
<head>
<title>JavaScript form validation - checking non-empty</title>
</head>
<body onload='document.form1.text1.focus()'>
<h2>Input Credit Card No.[Starting with 2131 or 1800, length 15 digits or starting
with 35, length 16 digits (Murali card) and Submit</h2>
<form name="form1" action="#">
enter card no:<input type='text' name='text1'/></li>
<br><input type="submit" name="submit" value="pay"
onclick="cardnumber(document.form1.text1)"/></li>
</form>
<script src="payment-validation.js"></script>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 33
WEB TECHNOLOGIES LAB 2021
Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 34
WEB TECHNOLOGIES LAB 2021
7. 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.

users.xml
<?xml version="1.0" encoding="UTF-8" ?>
<userlist>
<user>
<userid>scce01</userid>
<username>MuraliMohanReddy</username>
<address>KNR</address>
<phone>9030342066</phone>
<email>[email protected]</email></user>
<user>
<userid>scce02</userid>
<username>MReddy</username>
<address>HYD</address>
<phone>9999999999</phone>
<email>[email protected]</email></user>
<user>
<userid>scce03</userid>
<username>MuraliMohanReddy</username>
<address>KNR</address>
<phone>5555555555</phone>
<email>[email protected]</email></user>
<user>
<userid>scce04</userid>
<username>MuraliMohanReddy</username>
<address>WRL</address>
<phone>9000042066</phone>
<email>[email protected]</email></user>
<user>
<userid>scce05</userid>
<username>MuraliMohanReddy</username>
<address>SDPT</address>
<phone>4000000000</phone>
<email>[email protected]</email></user>
<user>
<userid>scce06</userid>
<username>MuraliReddy</username>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 35
WEB TECHNOLOGIES LAB 2021
<address>KNR</address>
<phone>5000000000</phone>
<email>[email protected]</email></user>
<user>
<userid>scce07</userid>
<username>MohanReddy</username>
<address>KNR</address>
<phone>6000000000</phone>
<email>[email protected]</email></user>
<user>
<userid>scce08</userid>
<username>MuraliMohanReddy</username>
<address>WRL</address>
<phone>7000000000</phone>
<email>[email protected]</email></user>
<user>
<userid>scce09</userid>
<username>MCUBEReddy</username>
<address>KNR</address>
<phone>8000000000</phone>
<email>[email protected]</email></user>
<user>
<userid>scce10</userid>
<username>MMMReddy</username>
<address>HYD</address>
<phone>9000000000</phone>
<email>[email protected]</email></user>
</userlist>

access.html

<!DOCTYPE html>
<html>
<body><center>
<form name="form">
userid <input type="text" name="tt"><br>
<input type="submit" onClick="validateFunc()">
</form></center>
<br><br><br><br><br><br><br><br><br>
<b>userid</b><p id="demo1"></p>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 36
WEB TECHNOLOGIES LAB 2021
<b>username</b><p id="demo2"></p>
<b>address</b><p id="demo3"></p>
<b>phone</b><p id="demo4"></p>
<b>email</b><p id="demo5"></p>

<script>
function validateFunc()
{
var nn = document.forms["form"]["tt"];
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};

xhttp.open("GET", "users.xml", true);


xhttp.send();

function myFunction(xml) {
var x, i, txt, xmlDoc;
xmlDoc = xml.responseXML;
txt1 = "";
txt2 = "";
txt3 = "";
txt4 = "";
txt5 = "";
x = xmlDoc.getElementsByTagName("userid");
y = xmlDoc.getElementsByTagName("username");
z = xmlDoc.getElementsByTagName("address");
a = xmlDoc.getElementsByTagName("phone");
b = xmlDoc.getElementsByTagName("email");
for (i = 0; i < x.length; i++) {
if(nn.value == x[i].childNodes[0].nodeValue)
{
txt1 += x[i].childNodes[0].nodeValue ;
txt2 += y[i].childNodes[0].nodeValue ;
txt3 += z[i].childNodes[0].nodeValue ;
txt4 += a[i].childNodes[0].nodeValue ;

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 37
WEB TECHNOLOGIES LAB 2021
txt5 += b[i].childNodes[0].nodeValue ;
}
}
document.getElementById("demo1").innerHTML = txt1;
document.getElementById("demo2").innerHTML = txt2;
document.getElementById("demo3").innerHTML = txt3;
document.getElementById("demo4").innerHTML = txt4;
document.getElementById("demo5").innerHTML = txt5;
}
}
</script>
</body>
</html>

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 38
WEB TECHNOLOGIES LAB 2021
8. 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.

Step 1: For Installing Apache (PHP), My SQL (Database), TOMCAT (Servlets, JSPs) web
server by XAMPP

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 39
WEB TECHNOLOGIES LAB 2021
Step 2: After Downloading XAMPP from https://www.apachefriends.org/index.html

Step 3: Now, double click on “xampp-windows-x64-8.0.13-0-VS16-installer.exe” file. then


next click on “yes” button and then next click on “ok” button

Step 4: Now, next click on “next” button in following screens

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 40
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 41
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 42
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 43
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 44
WEB TECHNOLOGIES LAB 2021
Step 5: Now, next click on “finish” button in following screen

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 45
WEB TECHNOLOGIES LAB 2021
Step 6: Before starting TOMCAT web server. Set the Environment Variables for JAVA
servlets and JSPs (for Tomcat web server

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 46
WEB TECHNOLOGIES LAB 2021

Step 7: Now start the TOMCAT web server. By clicking start button correspond to
TOMCAT

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 47
WEB TECHNOLOGIES LAB 2021
Step 8: To manage SERVLET and JSP web applications on TOMCAT Web Server click
on “config” button and open “tomcat-users.xml” and config or edit the following
statements in file.

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 48
WEB TECHNOLOGIES LAB 2021
Step9: Then restart TOMCAT Web Server and type the following URL
http://localhost:8080/ and then click on Manager App button to manage web applications
by login as username: admin and password: admin as mentioned in “tomcat-users.xml”
file, then click on Sign in button

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 49
WEB TECHNOLOGIES LAB 2021

main.html

<html>
<head>
<title>Servlets Cookies</title>
</head>
<body>
<h1>Servlets add Items to Cookies</h1>
<form method="GET" action="./add">
<P>add items to cart:<br>
<input type="checkbox" name="cart" value="Apple">Apple <b>price Rs.20</b><br>
<input type="checkbox" name="cart" value="Mango">Mango <b>price Rs.40</b><br>
<input type="checkbox" name="cart" value="Orange">Orange <b>price
Rs.30</b><br>
<input type="checkbox" name="cart" value="Banana">Banana <b>price
Rs.10</b></p>

<P><input type="submit" value="add to cart"></p>


</form>
</body>
</html>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 50
WEB TECHNOLOGIES LAB 2021
AddCookie.java

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class AddCookie extends HttpServlet


{
public void doGet (HttpServletRequest req, HttpServletResponse res) throws
IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
int sum=0;
out.println("<html><head><title>Servlets Cookies</title></head>");
out.println("<body>");
out.println("<h1>Servlets add Items to Cookies</h1>");
// extracting data from the checkbox field
String[] cart = req.getParameterValues("cart");
//items added to cart and price are

Cookie c1,c2,c3,c4,price;

for (int i=0;i<cart.length; i++) {


if(cart[i].equals("Apple"))
{
out.println("<li>" + cart[i] +"&nbsp; &nbsp; price Rs.20 <br>");
sum+=20;
c1=new Cookie("A",cart[i]);
c1.setMaxAge(36);
res.addCookie(c1);
}
if(cart[i].equals("Mango"))
{
out.println("<li>" + cart[i] +"&nbsp; &nbsp; price Rs.40 <br>");
sum+=40;
c2=new Cookie("M",cart[i]);
c2.setMaxAge(36);
res.addCookie(c2);
}
if(cart[i].equals("Orange"))
{
out.println("<li>" + cart[i] +"&nbsp; &nbsp; price Rs.30 <br>");
sum+=30;
c3=new Cookie("O",cart[i]);
c3.setMaxAge(36);
Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 51
WEB TECHNOLOGIES LAB 2021
res.addCookie(c3);
}
if(cart[i].equals("Banana"))
{
out.println("<li>" + cart[i] +"&nbsp; &nbsp; price Rs.10 <br>");
sum+=10;
c4=new Cookie("B",cart[i]);
c4.setMaxAge(36);
res.addCookie(c4);
}

}
price=new Cookie("cost",String.valueOf(sum));
price.setMaxAge(36);
res.addCookie(price);
out.println("</ul>");
out.println("<br>"+cart.length+"Items added to cart");
out.println("<br><a href=\"./get\">payment</a>");
out.println("</body></html>");
}
}

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 52
WEB TECHNOLOGIES LAB 2021
GetCookie.java

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;

public class GetCookie extends HttpServlet


{
public void doGet (HttpServletRequest req, HttpServletResponse res) throws
IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><head><title>Servlets Cookies</title></head>");
out.println("<body>");
out.println("<h1>Servlets get Items from Cookies and extracting data userid, password,
creditcardno from the web.xml </h1>");
// extracting data userid, password, creditcardno from the web.xml
String usrid,pwd,creditcard;

ServletConfig config=getServletConfig();
Enumeration<String> e=config.getInitParameterNames();
String str="";
while(e.hasMoreElements()){
str=e.nextElement();
out.println("<br>"+str+"&nbsp; :
&nbsp;<b>"+config.getInitParameter(str)+"</b>");
}
Cookie c[]=req.getCookies();
if(c!=null)
{ Cookie c1;
for(int i=0;i<c.length;i++)
{
c1=c[i];
out.println("<br>"+c1.getName()+"&nbsp; :
&nbsp;<b>"+c1.getValue()+"</b>");
}
}

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

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 53
WEB TECHNOLOGIES LAB 2021

web.xml

<?xml version="1.0" encoding="iso-8859-1"?>


<web-app>

<servlet>
<servlet-name>Set</servlet-name>
<servlet-class>AddCookie</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Set</servlet-name>
<url-pattern>/add</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Get</servlet-name>
<servlet-class>GetCookie</servlet-class>

<init-param>
<param-name>userid</param-name>
<param-value>mmmr</param-value>
</init-param>

<init-param>
<param-name>password</param-name>
<param-value>mmmr</param-value>
</init-param>

<init-param>
<param-name>creditcardno</param-name>
<param-value>123456</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>Get</servlet-name>
<url-pattern>/get</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>main.html</welcome-file>
</welcome-file-list>

</web-app>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 54
WEB TECHNOLOGIES LAB 2021

Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 55
WEB TECHNOLOGIES LAB 2021
9. 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.

Switch on MYSQL Server in XAMPP and open cmd prompt then connect database
server and then create database “mydb” and then create tables “login, book, details”
and store some data in tables

Microsoft Windows [Version 6.3.9600]


(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\My Dell>set path=C:\xampp\mysql\bin

C:\Users\My Dell>mysql -u root -p -h 127.0.0.1


Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.22-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
5 rows in set (0.048 sec)

MariaDB [(none)]> create database mydb;


Query OK, 1 row affected (0.006 sec)

MariaDB [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 56
WEB TECHNOLOGIES LAB 2021
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
6 rows in set (0.003 sec)

MariaDB [(none)]> use mydb;


Database changed
MariaDB [mydb]> create table login(id varchar(10),pwd varchar(10),name varchar(1
0),addr varchar(20),phno varchar(10));
Query OK, 0 rows affected (0.228 sec)

MariaDB [mydb]> desc login;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | varchar(10) | YES | | NULL | |
| pwd | varchar(10) | YES | | NULL | |
| name | varchar(10) | YES | | NULL | |
| addr | varchar(20) | YES | | NULL | |
| phno | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
5 rows in set (0.033 sec)

MariaDB [mydb]> insert into login values('101','101','murali','knr','9030342066'


);
Query OK, 1 row affected (0.231 sec)

MariaDB [mydb]> insert into login values('102','102','munna','hyd','9030342066')


;
Query OK, 1 row affected (0.085 sec)

MariaDB [mydb]> create table book(title varchar(10),author varchar(10),version v


archar(10),publisher varchar(10),cost varchar(10));
Query OK, 0 rows affected (0.327 sec)

MariaDB [mydb]> desc book;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| title | varchar(10) | YES | | NULL | |
| author | varchar(10) | YES | | NULL | |
| version | varchar(10) | YES | | NULL | |
| publisher | varchar(10) | YES | | NULL | |
| cost | varchar(10) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 57
WEB TECHNOLOGIES LAB 2021
5 rows in set (0.029 sec)

MariaDB [mydb]> insert into book values('wt','murali','2nd','scce','100');


Query OK, 1 row affected (0.082 sec)

MariaDB [mydb]> insert into book values('php','murali','3rd','scce','200');


Query OK, 1 row affected (0.089 sec)

MariaDB [mydb]> insert into book values('xml','murali','3rd','scce','200');


Query OK, 1 row affected (0.060 sec)

MariaDB [mydb]> insert into book values('jsp','murali','3rd','scce','200');


Query OK, 1 row affected (0.060 sec)

MariaDB [mydb]> select * from login;


+------+------+--------+------+------------+
| id | pwd | name | addr | phno |
+------+------+--------+------+------------+
| 101 | 101 | murali | knr | 9030342066 |
| 102 | 102 | munna | hyd | 9030342066 |
+------+------+--------+------+------------+
2 rows in set (0.002 sec)

MariaDB [mydb]> select * from book;


+-------+--------+---------+-----------+------+
| title | author | version | publisher | cost |
+-------+--------+---------+-----------+------+
| wt | murali | 2nd | scce | 100 |
| php | murali | 3rd | scce | 200 |
| xml | murali | 3rd | scce | 200 |
| jsp | murali | 3rd | scce | 200 |
+-------+--------+---------+-----------+------+
4 rows in set (0.001 sec)

MariaDB [mydb]> create table details(id varchar(10),title varchar(10),amount int


eger(5),cno varchar(10),date varchar(10),count integer(5));
Query OK, 0 rows affected (0.302 sec)

MariaDB [mydb]> desc details;


+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | varchar(10) | YES | | NULL | |
| title | varchar(10) | YES | | NULL | |
| amount | int(5) | YES | | NULL | |
| cno | varchar(10) | YES | | NULL | |

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 58
WEB TECHNOLOGIES LAB 2021
| date | varchar(10) | YES | | NULL | |
| count | int(5) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
6 rows in set (0.026 sec)

MariaDB [mydb]>

HTML and JSP with JDBC programs

main.html

<html>
<body>
<br><br><br><br><br><br>
<h1 align="center"><u>MURALI ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align="center"><PRE>
<b> Welcome to MURALI online book storage.
Press LOGIN if you are having id
Otherwise press REGISTRATION
</b></PRE></h2>
<br><br><pre>
<div align="center"><a href="login.html">LOGIN</a>
<a href="reg.html">REGISTRATION</a></div></pre>
</body>
</html>

login.html

<html>
<body><br /><br /><br />
<form name="myform" method="post" action="./login.jsp">
<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>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 59
WEB TECHNOLOGIES LAB 2021
reg.html

<html>
<body><br /><br />
<form name="myform" method="post" action="./reg.jsp">
<table align="center" >

<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<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

<html>
<body><br /><br />
<form name="myform" method="post" action="./reg.jsp">
<table align="center" >

<tr>
<td>NAME</td>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 60
WEB TECHNOLOGIES LAB 2021
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<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

<html>
<body><br /><br /><br />
<form method="post" action="./catalog.jsp">
<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>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 61
WEB TECHNOLOGIES LAB 2021
order.html

<html>

<body><br /><br />


<form method="post" action="./order.jsp">
<div align="center"><pre>
ID :<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;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>

login.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 62
WEB TECHNOLOGIES LAB 2021
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{ out.println("<br><br>VALID LOGIN ID<br><br>");
out.println("<h3><ul>");
out.println("<li><a href=\"profile.html\"><fontcolor=\"black\">USER PROFILE</font>
</a></li><br><br>");
out.println("<li><a href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
out.println("<li><a href=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font> </a></li></ul><br><br>");
}
out.println("</body></html>");
con.close();
%>

reg.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% response.setContentType("text/html");
out.println("<html><body>");
String name=request.getParameter("name");
String addr=request.getParameter("addr");
String phno=request.getParameter("phno");
String id1=request.getParameter("id");
String pwd1=request.getParameter("pwd");
int no=Integer.parseInt(phno);
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{ if(id1.equals(rs.getString(1))&&pwd1.equals(rs.getString(2)))
{ flag=1;
}
}
if(flag==1)
{ out.println("<br><br>SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH
NEW ID<br><br>");
out.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 63
WEB TECHNOLOGIES LAB 2021
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+id1+"','"+pwd1+"','"+name+"','"+addr+"','"+phno+"');");
out.println("<br><br>YOUR DETAILS ARE ENTERED<br><br>");
out.println("<a href=\"login.html\">press LOGIN to login</a>");
}
out.println("</body></html>");
con.close();
%>

profile.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+"";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
out.println("<br><br><br>");
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("NAME :"+rs.getString(3)+"<br>");
out.println("ADDRESS :"+rs.getString(4)+"<br>");
out.println("PHONE NO :"+rs.getString(5)+"<br>");
out.println("</div>");
flag=1;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"profile.html\">press HERE to RETRY</a>");
}
out.println("</body></html>");
con.close();
%>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 64
WEB TECHNOLOGIES LAB 2021
catalog.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String title=request.getParameter("title");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
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("<br><br>SORRY INVALID TITLE TRY AGAIN <br><br>");
out.println("<a href=\"catalog.html\">press HERE to RETRY</a>");
}
out.println("</body></html>");
con.close();
%>

order.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% int count;
out.println("<html><body>");
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");
count=Integer.parseInt(count1);
Class.forName("com.mysql.jdbc.Driver");

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 65
WEB TECHNOLOGIES LAB 2021
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/mydb","root","");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=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)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href= \"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("cost"));
amount=count*x;

out.println("<br><br>AMOUNT:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details
values('"+id+"','"+title+"',"+amount+",'"+cno+"','"+date+"',"+count1+");");
out.println("<br>YOUR ORDER has taken<br>");
}
if(flag1==0)
{
out.println("<br><br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"order.html\">press HERE to RETRY</a>");
}
}
out.println("</body></html>");
con.close();
%>

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 66
WEB TECHNOLOGIES LAB 2021
Output

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 67
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 68
WEB TECHNOLOGIES LAB 2021

Prepared by M. Murali Mohan Reddy, Assistant Professor, CSE DEPT, SCCE, Karimnagar. 69

You might also like