0% found this document useful (0 votes)
43 views78 pages

Web Tech Lab

The document is a lab manual for the Web Technology course at Srinath University, detailing various HTML, JavaScript, and XML programming exercises for BCA 4th semester students. It includes tasks such as creating lists, hyperlinks, tables, forms, and servlets, along with examples of code for each exercise. The manual serves as a practical guide for students to develop their web programming skills.

Uploaded by

g93758762
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)
43 views78 pages

Web Tech Lab

The document is a lab manual for the Web Technology course at Srinath University, detailing various HTML, JavaScript, and XML programming exercises for BCA 4th semester students. It includes tasks such as creating lists, hyperlinks, tables, forms, and servlets, along with examples of code for each exercise. The manual serves as a practical guide for students to develop their web programming skills.

Uploaded by

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

SRINATH UNIVERSITY, ADITYAPUR

DEPARTMENT OF
INFORMATION TECHNOLOGY

LAB MANUAL

WEB TECHNOLOGY(SUCPBCA406)

BCA 4TH SEM


WEB TECHNOLOGY LAB MANUAL

Lab Exercises
1. Write a HTML program for the demonstration of Lists.
a. Unordered List
b. Ordered List
c. Definition List
d. Nested List
2. Write a HTML program for demonstrating Hyperlinks.
a. Navigation from one page to another.
b. Navigation within the page.
3. Write a HTML program for time-table using tables.
4. Write a HTML program to develop a static Home Page using frames.
5. Write a HTML program to develop a static Registration Form.
6. Write a HTML program to develop a static Login Page.
7. Write a HTML program to develop a static Web Page for Catalog.
8. Write a HTML program to develop a static Web Page for Shopping Cart.
9. Write HTML for demonstration of cascading stylesheets.
a. Embedded stylesheets.
b. External stylesheets.
c. Inline styles.
10. Write a javascript program to validate USER LOGIN page.
11. Write a javascript program for validating REGISTRATION FORM
12. Write a program for implementing XML document for CUSTOMER DETAILS.
13. Write an internal Document Type Definition to validate XML for CUSTOMER
DETAILS?
14. Write an external Document Type Definition to validate XML for CUSTOMER
DETAILS?
15. Write an XML for person information and access the data using XSL.
16. Write an XML for student information and access second students data using DOM.
17. Write a program to display contents of XML file in a table using Extensible Style
Sheets.

DEPT OF IT, SU 2
WEB TECHNOLOGY LAB MANUAL

18. Write a simple servlet that displays a message.


19. Write a servlet that reads parameters from employee login page.
20. Write a servlet for creating a cookie and retrieving it.
21. Write a servlet for session tracking.
22. Write a JSP that reads parameters from user login page.
23. Write a JSP that reads a value, creates a cookie and retrieves it.
24. Write a JSP for session tracking.
25. Write a servlet that connects to the database and retrieves the data and displays it.

DEPT OF IT, SU 3
WEB TECHNOLOGY LAB MANUAL

1. Write a HTML program for the demonstration of Lists.


e. Unordered List
f. Ordered List
g. Definition List
h. Nested List
Unordered List:
<html>
<head>
<title> Creating Unorder List </title>
</head>
<body bgcolor=”pink”>
<h1 align=”center”> Creating Unorder List</h1>
<h1 align=”center”>List of Colleges in Kurnool</h1>
<ul type=”square”>
<li>GPREC</li>
<li>RGMCET</li>
<li>GPCET</li>
</ul>
</body>
</html>
Output:

DEPT OF IT, SU 4
WEB TECHNOLOGY LAB MANUAL

Ordered List:
<html>
<head>
<title> Creating Order List </title>
</head>
<body bgcolor=”pink”>
<h1 align=”center”> Creating Order List</h1>
<h1 align=”center”>List of branches in RGMCET</h1>
<ol type=”A”>
<li>CSE</li>
<li>IT</li>
<li>ECE</li>
<li>EEE</li>
<li>CIVIL</li>
<li>ME</li>
</ol>
</body>
</html>
Output:

DEPT OF IT, SU 5
WEB TECHNOLOGY LAB MANUAL

Definition List:
<html>
<head>
<title>Creating Definition List</title>
</head>
<body bgcolor=”pink”>
<h1 align=”center”>Definition List</h1>
<dl>
<dt>CSE<dd>Computer Science & Engineering
<dt>ECE<dd>Electronics & Communication Engineering
<dt>IT<dd>Information Technology
<dt>EEE<dd>Electrical & Electronics Engineering
<dt>CE<dd>Civil Engineering
</dl>
</body>
</html>
Output:

DEPT OF IT, SU 6
WEB TECHNOLOGY LAB MANUAL

Nested List:
<html>
<head>
<title>Nested Lists</title>
</head>
<body bgcolor=”pink”>
<h1 align=”center”>List of Colleges in Kurnool</h1>
<ol>
<li>Kurnool</li>
<ul>
<li>GPREC</li>
<li>BITS</li>
<li>GPCET</li>
</ul>
<li>Nandyala</li>
<ul>

DEPT OF IT, SU 7
WEB TECHNOLOGY LAB MANUAL

<li>RGMCET</li>
<li>SREC</li>
</ul>
</ol>
</body>
</html>
Output:

2. Write a HTML program for demonstrating Hyperlinks.


c. Navigation from one page to another.
d. Navigation within the page.
Navigation from one page to another:
<html>
<head>
<title>Setting Hyperlink colors</title>
</head>
<body bgcolor="pink" link=”green” vlink=”blue” alink=”red”>
<center><h1>Setting Hyperlink colors</h1>
<a href=”login.html”>Click here</a>to goto login page
</body>
</html>
Output:

DEPT OF IT, SU 8
WEB TECHNOLOGY LAB MANUAL

Navigation within the page:


<html>
<head>
<title>Nested Lists</title>
</head>
<body bgcolor="pink">
<center><h1>Linking to a section in a page</h1>
<a name=”top”>This is the top of the page</a>
Click here to goto the <a target=”#bottom”>bottom</a>of the page
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br>
<a name=”bottom”>This is the bottom of the page</a> Click
here to goto <a target=”#top”>top</a>of the page
</center>
</body>
</html>
Output:

DEPT OF IT, SU 9
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 10
WEB TECHNOLOGY LAB MANUAL

3. Write a HTML program for time-table using tables.


<html>
<head>
<title>Timetable</title>
</head>
<body>
<h1 align="center"><font color="Salmon">Timetable of III
CSE</font></h1><br>
<table align="center" border="2" cellspacing="0" cellpadding="15">
<tr align="center" valign=="middle">
<th>DAY</th>
<th>I</th>
<th>II</th>
<th
rowspan="7"><b>T<br>E<br>A<br><br>B<br>R<br>E<br>A<br>K</b></th>
<th>III</th>
<th>IV</th>
<th
rowspan="7"><b>L<br>U<br>N<br>C<br>H<br><br>B<br>R<br>E<br>A<br>K</
b></th>
<th>V</th>
<th>VI</th>
<th>VII</th>
</tr>
<tr align="center">
<th>MON</th>
<td>IS</td>
<td>WT</td>
<td>SEM</td>
<td>OOAD</td>

DEPT OF IT, SU 11
WEB TECHNOLOGY LAB MANUAL

<td>SCI</td>
<td>C#</td>
<td>COMP</td>
</tr>
<tr align="center">
<th>TUE</th>
<td>AP</td>
<td>AP Lab</td>
<td colspan="2">AP Lab</td>
<td>WT</td>
<td>IS</td>
<td>OOAD</td>
</tr>
<tr align="center">
<th>WED</th>
<td>WT</td>
<td>IS</td>
<td>C#</td>
<td>SCI</td>
<td colspan="3">MOOC'S</td>
</tr>
<tr align="center">
<th>THU</th>
<td>IS</td>
<td>LIB</td>
<td>OOAD</td>
<td>WT</td>
<td colspan="3">WT Lab</td>
</tr>
<tr align="center">

DEPT OF IT, SU 12
WEB TECHNOLOGY LAB MANUAL

<th>FRI</th>
<td>AP</td>
<td>AP</td>
<td>C#</td>
<td>OOAD</td>
<td colspan="3">C# Lab</td>
</tr>
<tr align="center">
<th>SAT</th>
<td>OOAD</td>
<td>SCI</td>
<td>WT</td>
<td>SEM</td>
<td>AP</td>
<td>AP</td>
<td>C#</td>
</tr>
</table>
</body>
</html>
Output:

DEPT OF IT, SU 13
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 14
WEB TECHNOLOGY LAB MANUAL

4. Write a HTML program to develop a static Home Page using frames.


<html>
<head>
<title>RGM ENGINEERING COLLEGE</title>
</head>
<frameset cols="30%,70%">
<frameset rows="25%,25%,50%">
<frame src="e:\cse546\logo.html">
<frame src="e:\cse546\home1.html">
<frame src="e:\cse546\courses.html">
</frameset>
<frameset rows="25%,25%,50%">
<frame src="e:\cse546\name.html">
<frame src="e:\cse546\table.html">
<frame src="e:\cse546\default.html" name="display">
</frameset>
</frameset>
</html>
Output:

DEPT OF IT, SU 15
WEB TECHNOLOGY LAB MANUAL

5. Write a HTML program to develop a static Registration Form.


<html>
<head>
<title>Registration</title>
</head>
<body bgcolor=lightblue>
<h1 align=center><u>Registration Form</u></h1>
<br><br><br>
<div>
<strong>
First Name &nbsp <input type=text value=" " name="txt1"><br><br>
Last Name &nbsp <input type=text value=" " name="txt2"><br><br>
UserName &nbsp <input type=text value="" name="txt3"><br><br>
Password &nbsp <input type=password value="" name="pwd1"><br>
Confirm Password &nbsp <input type=password value="" name="pwd2"><br><br>
Address &nbsp <textarea rows=3 cols=60></textarea><br><br>
Date of Birth &nbsp
dd<select name="sel1">
<option>--</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>

DEPT OF IT, SU 16
WEB TECHNOLOGY LAB MANUAL

mm<select name="sel2">
<option>--</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
yyyy<select name="sel3">
<option> --- </option>
<option>1987</option>
<option>1988</option>
<option>1989</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>

DEPT OF IT, SU 17
WEB TECHNOLOGY LAB MANUAL

<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
</select><br><br>
Sex &nbsp
<input name="rb1" type="radio" value="radiobutton">Male
<input name="rb1" type="radio" value="radiobutton">Female
<br><br>
Martial Status &nbsp
<input name="rb2" type="radio" value="radiobutton">Single
<input name="rb2" type="radio" value="radiobutton">Married
<br><br>
Mobile Number &nbsp <input type=text name="txt4"><br><br>
Branch &nbsp
<input name="rb3" type="radio" value="radiobutton">CSE

DEPT OF IT, SU 18
WEB TECHNOLOGY LAB MANUAL

<input name="rb3" type="radio" value="radiobutton">IT


<input name="rb3" type="radio" value="radiobutton">ECE
<input name="rb3" type="radio" value="radiobutton">EEE
<input name="rb3" type="radio" value="radiobutton">MECH
<br><br>
Languages Known &nbsp
<input name="cb1" type="checkbox" value="checkbox">English
<input name="cb1" type="checkbox" value="checkbox">Telugu
<input name="cb1" type="checkbox" value="checkbox">Hindi
<input name="cb1" type="checkbox" value="checkbox">Kannada
<input name="cb1" type="checkbox" value="checkbox">Tamil
<br><br>
<center>
<input type=submit value="SUBMIT" name="btn1">&nbsp
<input type=reset value="CANCEL" name="btn1">
</center>
</strong>
</body>
</html>

Output:

DEPT OF IT, SU 19
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 20
WEB TECHNOLOGY LAB MANUAL

6. Write a HTML program to develop a static Login Page.


<html>
<head>
<title>login</title>
</head>
<body>
<br><br><br><br>
<h1 align=center><u>LOGIN</u></h1>
<br><br><br>
<h4>
<center>
username&nbsp&nbsp<input type=text><br>
password&nbsp&nbsp<input type=password><br><br><br>
</h4>
<input type=submit value=submit>
&nbsp&nbsp
<input type=reset value=cancel>
</center>
</body>
</html>

DEPT OF IT, SU 21
WEB TECHNOLOGY LAB MANUAL

Output:

DEPT OF IT, SU 22
WEB TECHNOLOGY LAB MANUAL

7. Write a HTML program to develop a static Web Page for Catalog.


<html>
<head>
<title>catalouge</title>
</head>
<body>
<center>
<table border=2 cellpadding=10 cellspacing=10>
<tr>
<td> <img src="D:\cse546\image.jpg"height=100 width=100></td>
<td>Book:XML Bible<br>
Author:Wingston<br>
Publication:wiely</td>
<td>$40.5</td>
<td><input type="button"value="add to cart"></td>
</tr>
<tr>
<td> <img src="D:\cse546\image1.jpg"height=100 width=100></td>
<td>Book:A1<br>
Author:S.Rusell<br>
Publication:Princeton hall</td>
<td>$63</td>
<td><input type="button"value="add to cart"></td>
</tr>
<tr>
<td> <img src="D:\cse546\image2.jpg"height=100 width=100></td>
<td>Book:JAVA 2<br>
Author:Watson<br>
Publication:BPB</td>
<td>$35.5</td>

DEPT OF IT, SU 23
WEB TECHNOLOGY LAB MANUAL

<td><input type="button"value="add to cart"></td>


</tr>
<tr>
<td> <img src="D:\cse546\image3.jpg"height=100 width=100></td>
<td>Book:Html in 24 hrs<br>
Author:Sam Peter<br>
Publication:SAM</td>
<td>$50</td>
<td><input type="button"value="add to cart"></td>
</tr>
</table>
</center>
</body>
</html>
Output:

DEPT OF IT, SU 24
WEB TECHNOLOGY LAB MANUAL

8. Write a HTML program to develop a static Web Page for Shopping Cart.
<html>
<head>
<title>Cart</title>
</head>
<body>
<center>
<table border=0 width=50 height=10 cellpadding=10 cellspacing=10>
<tr>
<th>Book name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
<tr>
<td>JAVA 2</td>
<td>$35.5</td>
<td>2</td>
<td>$70</td>
</tr>
<tr>
<td>XML Bible</td>
<td>$40.5</td>
<td>1</td>
<td>$40.5</td>
</tr>
</table>
<h3>total amount-130.5</h3>
</center>
</body>

DEPT OF IT, SU 25
WEB TECHNOLOGY LAB MANUAL

</html>
Output:

DEPT OF IT, SU 26
WEB TECHNOLOGY LAB MANUAL

9. Write HTML for demonstration of cascading stylesheets.


d. Embedded stylesheets.
e. External stylesheets.
f. Inline styles.
Embedded stylesheets:
<html>
<head>
<title>Embedded Style sheets</title>
<style type=”text/css”>
body{backgroun
d-color: pink;}
h1
{color:orange;
text-align:
center;
}
p{
font-family: "Times
New Roman";
font-size: 20px;
}
</style>
</head>
<body>
<h1>Embedded Style Sheets</h1><br>
<p>This is a paragraph
</body>
</html>
Output:

DEPT OF IT, SU 27
WEB TECHNOLOGY LAB MANUAL

External Stylesheets:
extern.css:
body {background-color: #d0e4fe;}
h1 {
color: orange; text-align: center;
}
p{
font-family: "Times New Roman"; font-size: 20px;
}
extern.html:
<html>
<head>
<title>External Style Sheets</title>
<link rel=”stylesheet” type=”text/css” href=”extern.css”>
</head>
<body>
<h1>External Style Sheets</h1><br>
<p>This is a paragraph
</body>
</html>

DEPT OF IT, SU 28
WEB TECHNOLOGY LAB MANUAL

Output:

Inline styles:
<html>
<head>
<title>HTML Tables</table>
</head>
<body bgcolor=‟pink‟>
<center>
<h1>Creating HTML Tables</h1><br>
<table border=”2” cellpadding=”4” cellspacing=”4”>
<tr>
<th colspan=”2” style=”background-color:red”>
WebSites</th>
</tr>
<tr>
<th style=”background-
color:blue”>MailSites</th>
<th style=”background-
color:green”>JobSites</th>

DEPT OF IT, SU 29
WEB TECHNOLOGY LAB MANUAL

</tr>
<tr>
<td style=”background-color:grey”>Gmail</td>
<td style=”background-color:aqua”>Naukri</td>
</tr>
<tr>
<td style=”background-
color:yellow”>Yahoo</td>
<td style=”background-
color:purple”>JobStreet</td>
</tr>
</table>
</center>
</body>
</html>
Output:

DEPT OF IT, SU 30
WEB TECHNOLOGY LAB MANUAL

10. Write a javascript program to validate USER LOGIN page.


<html>
<head>
<title>Login Validation</title>
<script language="javascript">
function formValidator()
{
var username=document.getElementById('uname');
var password=document.getElementById('pwd');
if(isEmpty(username)&&isEmpty(password))
{
alert("enter something");
document.form1.uname.focus();
}
if(!isEmpty(username)&&isEmpty(password)&&isAlphabet(username))
{
alert("Please enter password");
document.form1.pwd.focus();
}
if(!isEmpty(username)&&!isEmpty(password)&&isAlphabet(username))
{
return true;
}
else
{
if(!isEmpty(username)&&!isEmpty(password)&&!isAlphabet(username))
{
alert("Please Enter only alphabets for username");
document.form1.uname.focus();
}

DEPT OF IT, SU 31
WEB TECHNOLOGY LAB MANUAL

}
return false;
}
function isEmpty(elem)
{
if(elem.value.length==0)
{
return true;
}
return false;
}
function isAlphabet(elem)
{
var alphaExp=/^[a-z A-Z]+$/;
if(elem.value.match(alphaExp))
{
return true;
}
}
</script>
</head>
<body bgColor=megastar>
<h1 align=center>USER LOGIN VALIDATION</h1>
<br><br>
<form name="form1" onSubmit="return formValidator()">
<center>
<table border=0 colsSpacing=4>
<tr>
<td>Username:</td>
<td><input type=text value="" name="uname"></td>

DEPT OF IT, SU 32
WEB TECHNOLOGY LAB MANUAL

</tr>
<tr>
<td>Password:</td>
<td><input type=password value="" name="pwd"></td>
</tr>
<tr>
<td><input type=submit value="SUBMIT" name="btn1"></td>
<td><input type=reset value="CANCEL" name="btn2"></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Output:

DEPT OF IT, SU 33
WEB TECHNOLOGY LAB MANUAL

11. Write a javascript program for validating REGISTRATION FORM.


<html>
<head>
<title>JavaScript sample registration from validation </title>
<script type='text/javascript'>
function formValidation()
{
var uid = document.form1.userid;
var passid = document.form1.passid;
var uname = document.form1.username;
var uadd = document.form1.address;
var uzip = document.form1.zip;
var uemail = document.form1.email;
var umsex = document.form1.msex;
var ufsex = document.form1.fsex;
if(userid_validation(uid,5,12))
{
if(userid_validation(passid,7,12))
{
if(allLetter(uname))
{
if(alphanumeric(uadd))
{
if(allnumeric(uzip))
{
if(ValidateEmail(uemail))
{
if(validsex(umsex,ufsex))
{
}

DEPT OF IT, SU 34
WEB TECHNOLOGY LAB MANUAL

}
}
}
}
}
}
return false;
} function userid_validation(uid,mx,my)
{
var uid_len = uid.value.length;
if (uid_len == 0 || uid_len >= my || uid_len < mx)
{
alert("It should not be empty / length be between "+mx+" to "+my);
uid.focus();
return false;
}
return true;
}
function allLetter(uname)
{
var letters = /^[A-Za-z]+$/;
if(uname.value.match(letters))
{
return true;
}
else
{
alert('Please input alphabet characters only');
uname.focus();
return false;

DEPT OF IT, SU 35
WEB TECHNOLOGY LAB MANUAL

}
}
function alphanumeric(uadd)
{
var letters = /^[0-9a-zA-Z]+$/;
if(uadd.value.match(letters))
{
return true;
}
else
{
alert('Please input alphanumeric characters only');
uadd.focus();
return false;
}
}
function allnumeric(uzip)
{
var numbers = /^[0-9]+$/;
if(uzip.value.match(numbers))
{
return true;
}
else
{
alert('Please input numeric characters only');
uzip.focus();
return true;
}
}

DEPT OF IT, SU 36
WEB TECHNOLOGY LAB MANUAL

function ValidateEmail(uemail)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(uemail.value.match(mailformat))
{
return true;
}
else
{
alert("You have entered an invalid email address!");
uemail.focus();
return false;
}
} function validsex(umsex,ufsex)
{
x=0;

if(umsex.checked)
{
x++;
} if(ufsex.checked)
{
x++;
}
if(x==0)
{
alert('Select Male/Female');
umsex.focus();
return false;
}

DEPT OF IT, SU 37
WEB TECHNOLOGY LAB MANUAL

else
{
return true;

}
}
</script>
</head>
<body>
<form name='form1' onsubmit='return formValidation()' >
<table width="500" cellpadding="3" style="border-collapse: collapse;">
<tr>
<td>User id </td>
<td><input type="text" name="userid" size="12" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="passid" size="12" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="username" size="50" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" size="50" /></td>
</tr>
<tr>
<td>ZIP Code </td>
<td><input type="text" name="zip" /></td>

DEPT OF IT, SU 38
WEB TECHNOLOGY LAB MANUAL

</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="50" /></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="msex" value="Male" /> Male
<input type="radio" name="fsex" value="Female" /> Female</td>
</tr>
<tr>
<td>Language preference</td>
<td><input type="checkbox" name="en" value="en" checked />English
<input type="checkbox" name="nonen" value="noen" />Non English</td>
</tr>
<tr>
<td>Write about yourself<br>
(optional)</td>
<td><textarea name="desc" rows="4" cols="40"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Submit" /></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>

DEPT OF IT, SU 39
WEB TECHNOLOGY LAB MANUAL

Output:

DEPT OF IT, SU 40
WEB TECHNOLOGY LAB MANUAL

12. Write a program for implementing XML document for CUSTOMER DETAILS.
<?xml version="1.0"?>
<DOCUMENT>
<CUSTOMER>
<NAME>
<FIRST_NAME>Hari</FIRST_NAME>
<LAST_NAME>Krishna</LAST_NAME>
</NAME>
<DATE>10/09/2008</DATE>
<ORDERS>
<ITEM>
<PRODUCT>Mobile Set</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>Rs.14000/-</PRICE>
</ITEM>
<ITEM>
<PRODUCT>Mp3 Player</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>Rs.1300/-</PRICE>
</ITEM>
</ORDERS>
</CUSTOMER>
<CUSTOMER>
<NAME>
<FIRST_NAME>Anil</FIRST_NAME>
<LAST_NAME>Kumar</LAST_NAME>
</NAME>
<DATE>10/09/2008</DATE>
<ORDERS>
<ITEM>

DEPT OF IT, SU 41
WEB TECHNOLOGY LAB MANUAL

<PRODUCT>Monitor</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>Rs.14000/-</PRICE>
</ITEM>
<ITEM>
<PRODUCT>Washing Machine</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>Rs.17000/-</PRICE>
</ITEM>
</ORDERS>
</CUSTOMER>
</DOCUMENT>
Output:

DEPT OF IT, SU 42
WEB TECHNOLOGY LAB MANUAL

13. Write an internal Document Type Definition to validate XML for CUSTOMER
DETAILS?
<?xml version="1.0"?>
<!DOCTYPE DOCUMENT[
<!ELEMENT DOCUMENT (CUSTOMER)*>
<!ELEMENT CUSTOMER (NAME,DATE,ORDERS)>
<!ELEMENT NAME (FIRST_NAME,LAST_NAME)>
<!ELEMENT FIRST_NAME (#PCDATA)>
<!ELEMENT LAST_NAME (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT ORDERS (ITEM)*>
<!ELEMENT ITEM (PRODUCT,NUMBER,PRICE)>
<!ELEMENT PRODUCT (#PCDATA)>
<!ELEMENT NUMBER (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
]>
<DOCUMENT>
<CUSTOMER>
<NAME>
<FIRST_NAME>aaa</FIRST_NAME>
<LAST_NAME>ZZZ</LAST_NAME>
</NAME>
<DATE>10/09/2008</DATE>
<ORDERS>
<ITEM>
<PRODUCT>Monitor</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>Rs.14000/-</PRICE>
</ITEM>
</ORDERS>

DEPT OF IT, SU 43
WEB TECHNOLOGY LAB MANUAL

</CUSTOMER>
</DOCUMENT>
Output:

DEPT OF IT, SU 44
WEB TECHNOLOGY LAB MANUAL

14. Write an external Document Type Definition to validate XML for CUSTOMER
DETAILS?
Extern.dtd:
<!ELEMENT document (customer)*>
<!ELEMENT customer (name,date,orders)>
<!ELEMENT name (firstname,lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT orders (item)*>
<!ELEMENT item (product,number,price)>
<!ELEMENT product (#PCDATA)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT price (#PCDATA)>
Cust.xml:
<?xml version="1.0"?>
<!DOCTYPE document SYSTEM "extern.dtd">
<document>
<customer>
<name>
<firstname>aaa</firstname>
<lastname>bbb</lastname>
</name>
<date>1 jan 2021</date>
<orders>
<item>
<product>chocolates</product>
<number>666</number>
<price>250</price>
</item>

DEPT OF IT, SU 45
WEB TECHNOLOGY LAB MANUAL

<item>
<product>sweets</product>
<number>777</number>
<price>450</price>
</item>
</orders>
</customer>
</document>
Output:

DEPT OF IT, SU 46
WEB TECHNOLOGY LAB MANUAL

15. Write an XML for person information and access the data using XSL.
Ppl.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="people.xsl"?>
<people>
<person born="1982">
<name>
<firstname>aaa</firstname>
<lastname>bbb</lastname>
</name>
<profession>Project Lead</profession>
</person>
<person born="1980">
<name>
<firstname>ccc</firstname>
<lastname>ddd</lastname>
</name>
<profession>Project Manager</profession>
</person>
</people>
People.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="no"/>
<xsl:template match="/">
<html>
<head>
<title>Presenting XML data</title>
</head>
<body>

DEPT OF IT, SU 47
WEB TECHNOLOGY LAB MANUAL

<table border="2">
<tr>
<th>Born</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Profession</th>
</tr>
<xsl:for-each select="people/person">
<tr>
<td><xsl:value-of select="@born"/></td>
<td><xsl:value-of select="name/firstname"/></td>
<td><xsl:value-of select="name/lastname"/></td>
<td><xsl:value-of select="profession"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:

DEPT OF IT, SU 48
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 49
WEB TECHNOLOGY LAB MANUAL

16. Write an XML for student information and access second students data using
DOM.
Schl.xml:
<?xml version="1.0"?>
<school>
<class>
<class_title>XML</class_title>
<students>
<student>
<firstname>aaa</firstname>
<lastname>bbb</lastname>
</student>
<student>
<firstname>aaa</firstname>
<lastname>bbb</lastname>
</student>
</students>
</class>
</school>
School.html:
<html>
<head>
<title>Accessing XML data</title>
<script type="text/javascript">
function getStudentData()
{
var xmldoc;
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("school.xml");
nodeSchool=xmldoc.documentElement;

DEPT OF IT, SU 50
WEB TECHNOLOGY LAB MANUAL

nodeClass=nodeSchool.firstChild;
nodeStudents=nodeClass.lastChild;
nodeStudent=nodeStudents.lastChild;
nodeFirstname=nodeStudent.firstChild;
nodeLastname=nodeFirstname.nextSibling;
message.innerHTML="Name:"+nodeFirstname.firstChild.nodeValue+"
"+nodeLastname.firstChild.nodeValue;
}
</script>
</head>
<body bgcolor="pink">
<center>
<h1>Accessing XML Data</h1>
<div id="message"></div>
<input type="button" value="GET DATA" onClick="getStudentData()">
</center>
</body>
</html>
Output:

DEPT OF IT, SU 51
WEB TECHNOLOGY LAB MANUAL

17. Write a program to display contents of XML file in a table using Extensible Style
Sheets ?
Book.xml:
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="book.xsl"?>
<book>
<bookinfo>
<title>C</title>
<authorname>Balaguru Swamy</authorname>
<isdnno>1234</isdnno>
<publisher>pearson</publisher>
<edition>4th</edition>
<price>$50</price>
</bookinfo>
<bookinfo>
<title>c++</title>
<authorname>Balaguru Swamy</authorname>
<isdnno>5678</isdnno>
<publisher>technical</publisher>
<edition>3rd</edition>
<price>$100</price>
</bookinfo>
</book>
Book.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="no"/>
<xsl:template match="/">
<html>
<head>

DEPT OF IT, SU 52
WEB TECHNOLOGY LAB MANUAL

<title>Book</title>
</head>
<body>
<center>
<table border="1" bgcolor=”grey”>
<thead >
<tr>
<th>title</th>
<th>authorname</th>
<th>isdnno</th>
<th>publisher</th>
<th>edition</th>
<th>price</th>
</tr>
</thead>
<xsl:for-each select="book/bookinfo">
<tr>
<td style="background-color:pink"><xsl:value-of select="title"/></td>
<td style="background-color:red"><xsl:value-of select="authorname"/></td>
<td style="background-color:green"><xsl:value-of select="isdnno"/></td>
<td style="background-color:purple"><xsl:value-of select="publisher"/></td>
<td style="background-color:brown"><xsl:value-of select="edition"/></td>
<td style="background-color:yellow"><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>

DEPT OF IT, SU 53
WEB TECHNOLOGY LAB MANUAL

</xsl:stylesheet>
Output:

DEPT OF IT, SU 54
WEB TECHNOLOGY LAB MANUAL

18. Write a simple servlet that displays a message.


FirstServlet.java:
import java.io.*;
import javax.servlet.*;
public class FirstServlet extends GenericServlet{
public void service(ServletRequest req,ServletResponse res)throws
ServletException,IOException{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<html><head><title>First Servlet</title></head>");
pw.println("<body><center><h1>This Message came from a
servlet</h1>");
pw.println("</center></body></html>");
pw.close();
}
}
Web.xml:
<web-app>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
Output:

DEPT OF IT, SU 55
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 56
WEB TECHNOLOGY LAB MANUAL

19. Write a servlet that reads parameters from employee login page.
Index.html:
<html>
<head>
<title>Servlet Parameters</title>
</head>
<body>
<center>
<form name="form1" method="POST"
action="http://localhost:9401/rpar/rparam">
<table>
<tr>
<td><b>Employee</td>
<td><input type="text" name="ename"
value=""></td>
</tr>
<tr>
<td><b>Id</td>
<td><input type="text" name="id" value=""></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
<td><input type="reset" value="clear"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Rparam.java:

DEPT OF IT, SU 57
WEB TECHNOLOGY LAB MANUAL

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class Rparam extends GenericServlet{
public void service(ServletRequest req,ServletResponse res)throws
ServletException,IOException{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
Enumeration e=req.getParameterNames();
while(e.hasMoreElements()){
String pname=(String)e.nextElement();
pw.println("<b>"+pname+"=");
String pvalue=req.getParameter(pname);
pw.println("<b>"+pvalue);
}
pw.close();
}
}
Web.xml:
<web-app>
<servlet>
<servlet-name>rp</servlet-name>
<servlet-class>Rparam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>rp</servlet-name>
<url-pattern>/rparam</url-pattern>
</servlet-mapping>
</web-app>
Output:

DEPT OF IT, SU 58
WEB TECHNOLOGY LAB MANUAL

DEPT OF IT, SU 59
WEB TECHNOLOGY LAB MANUAL

20. Write a servlet for creating a cookie and retrieving it.


Index.html:
<html>
<head>
<title> Cookies demo </title>
</head>
<body>
<center>
<form name="form1" method="POST" action="http://localhost:9401/cook/acook">
<b>Enter a value for my cookie:
<input type="text" name="data" size=25 value="">
<br><input type="submit" value="submit">
</form>
</center>
</body>
</html>
AddCookieServlet.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost (HttpServletRequest req, HttpServletResponse res)throws
ServletException,IOException
{
String data=req.getParameter("data");
Cookie cookie=new Cookie("MyCookie",data);
res.addCookie(cookie);
PrintWriter pw=res.getWriter();
pw.println("<br>MyCookie has been sent to:");

DEPT OF IT, SU 60
WEB TECHNOLOGY LAB MANUAL

pw.println(data);
pw.close();
}
}
GetCookieServlet.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetCookieServlet extends HttpServlet
{
public void doGet (HttpServletRequest req, HttpServletResponse res)throws
ServletException, IOException
{
Cookie[] cookies=req.getCookies();
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<b>");
for(int i=0;i<cookies.length;i++)
{
String name=cookies[i].getName();
String value=cookies[i].getValue();
pw.println("name="+name+";value="+value);
}
pw.close();
}
}
Web.xml:
<web-app>
<servlet>
<servlet-name>ackk</servlet-name>

DEPT OF IT, SU 61
WEB TECHNOLOGY LAB MANUAL

<servlet-class>AddCookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ackk</servlet-name>
<url-pattern>/acook</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>gck</servlet-name>
<servlet-class>GetCookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>gck</servlet-name>
<url-pattern>/gcook</url-pattern>
</servlet-mapping>
</web-app>
Output:
Web page that accepts value for my cookie.

Servlet response that creates a cookie and adds it to the response:

DEPT OF IT, SU 62
WEB TECHNOLOGY LAB MANUAL

Servlet that reads the cookie from request.

DEPT OF IT, SU 63
WEB TECHNOLOGY LAB MANUAL

21. Write a servlet for session tracking.


DateServlet.java:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateServlet extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException{
res.setContentType("text/html");
HttpSession hs=req.getSession(true);
PrintWriter pw=res.getWriter();
pw.print("<b>");
Date d=(Date)hs.getAttribute("date");
if(d!=null){
pw.print("Last accessed date:"+d+"<br>");
}
d= new Date();
hs.setAttribute("date",d);
pw.print("current date:"+d);
pw.close();
}
}
Web.xml:
<web-app>
<servlet>
<servlet-name>sess</servlet-name>
<servlet-class>DateServlet</servlet-class>
</servlet>
<servlet-mapping>

DEPT OF IT, SU 64
WEB TECHNOLOGY LAB MANUAL

<servlet-name>sess</servlet-name>
<url-pattern>/ddd</url-pattern>
</servlet-mapping>
</web-app>
Output:

DEPT OF IT, SU 65
WEB TECHNOLOGY LAB MANUAL

22. Write a JSP that reads parameters from user login page.
Index.html:
<html>
<head>
<title>Login Page</title>
</head>
<body>
<h1 align=center>Login</h1>
<form name="form1" action="loginJsp.jsp" method="post">
<table>
<tr>
<td><b>UserName:</td>
<td><input type=txt name=t1></td>
</tr>
<tr>
<td><b>Password:</td>
<td><input type=password name=t2></td>
</tr>
<tr>
<td><input type=submit value=submit></td>
<td><input type=reset value=cancel></td>
</tr>
</table>
</form>
</body>
</html>
loginJsp.jsp:
<%@ page import="javax.io.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>

DEPT OF IT, SU 66
WEB TECHNOLOGY LAB MANUAL

<%@ page import="javax.servlet.jsp.*"%>


<html>
<head>
<title>Login</title>
</head>
<body>
<%out.println("User Name is:"+request.getParameter("t1"));
out.println("Password is:"+request.getParameter("t2"));
%>
</body>
</html>
Output:
Login page to enter data:

DEPT OF IT, SU 67
WEB TECHNOLOGY LAB MANUAL

JSP after submitting the data:

DEPT OF IT, SU 68
WEB TECHNOLOGY LAB MANUAL

23. Write a JSP that reads a value, creates a cookie and retrieves it.
Index.html:
<html>
<body>
<form name="form1" action="second.jsp">
<b>Enter Value for cookie:
<input type="text" name="data" value="">
<br>
<input type="submit" value="Enter">
</body>
</html>
Second.jsp:
<%@page contentType="text/html" language="java"%>
<%
String data=request.getParameter("data");
Cookie cookie=new Cookie("Mycookie",data);
cookie.setMaxAge(60*60);
response.addCookie(cookie);
out.print("<b> Cookie value:"+data);
%>
<html>
<body>
<a href="third.jsp">Click here</a> to see the cookie's data
</body>
</html>
Third.jsp:
<%@page session="false"%>
<html>
<body>
<%

DEPT OF IT, SU 69
WEB TECHNOLOGY LAB MANUAL

Cookie[] cookies = null;


cookies = request.getCookies();
if( cookies != null ){
for (int i = 0; i < cookies.length; i++){
out.print("Name : " + cookies[i].getName() + ", ");
out.print("Value: " + cookies[i].getValue()+" <br>");
}
}else{
out.println("<h2>No cookies founds</h2>");
}
%>
</body>
</html>
Output:
Web page that accepts cookie value:

JSP that reads and creates a cookie:

DEPT OF IT, SU 70
WEB TECHNOLOGY LAB MANUAL

JSP that reads a cookie from the request:

DEPT OF IT, SU 71
WEB TECHNOLOGY LAB MANUAL

24. Write a JSP for session tracking.


<%@ page import="java.io.*,java.util.*" %>
<%
Date createTime = new Date(session.getCreationTime());
Date lastAccessTime = new Date(session.getLastAccessedTime());
%>
<html>
<head>
<title>Session Tracking</title>
</head>
<body>
<center>
<h1>Session Tracking Example</h1>
</center>
<table border="1" align="center">
<tr bgcolor="#ffcccc">
<th>Session info</th>
<th>Value</th>
</tr>
<tr >
<td>id</td>
<td><% out.print( session.getId()); %></td>
</tr>
<tr>
<td>Creation Time</td>
<td><% out.print(createTime); %></td>
</tr>
<tr>
<td>Time of Last Access</td>
<td><% out.print(lastAccessTime); %></td>

DEPT OF IT, SU 72
WEB TECHNOLOGY LAB MANUAL

</tr>
</table>
</body>
</html>
Output:

DEPT OF IT, SU 73
WEB TECHNOLOGY LAB MANUAL

25. Write a servlet that connects to the database and retrieves the data and displays
it.
Index.html:
<html>
<body>
<form action="show" method="post">
<font face="verdana" size="2">
Enter Table Name :<input type="text" name="table">
<input type="submit" value="Display">
</font>
</form>
</body>
</html>
ServletDatabaseConnect.java:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletDatabaseConnect extends HttpServlet


{
protected void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException

DEPT OF IT, SU 74
WEB TECHNOLOGY LAB MANUAL

{
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String tb=req.getParameter("table");

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","nvn","nvn")
;
Statement st=con.createStatement();
System.out.println("connection established successfully...!!");

ResultSet rs=st.executeQuery("select * from "+tb);

pw.println("<table border=1>");
pw.println("<tr><th>Username</th><th>Password</th></tr>");
while(rs.next())
{

pw.println("<tr><td>"+rs.getString(1)+"</td><td>"+rs.getString(2)+"</td></tr>");
}
pw.println("</table>");
pw.close();
}
catch (Exception e){
e.printStackTrace();
}

DEPT OF IT, SU 75
WEB TECHNOLOGY LAB MANUAL

}
}
Web.xml:
<web-app>
<servlet>
<servlet-name>ServletDBConnect</servlet-name>
<servlet-class>ServletDatabaseConnect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDBConnect</servlet-name>
<url-pattern>/show</url-pattern>
</servlet-mapping>
</web-app>

DEPT OF IT, SU 76
RAJEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Evaluation Procedure for Internal Laboratory Examinations:

1. Of the 25 marks for internal, 10 marks will be awarded for day-to-day work and 10 marks
to be awarded for the Record work and 5 marks to be awarded by conducting an internal
laboratory test.
2. Concerned Teachers have to do necessary corrections with explanations.
3. Concerned Lab teachers should enter marks in index page.
4. Internal exam will be conducted by two Staff members.

Dr.K. Subba Reddy


Professor & Head Dept. of CSE.
RAJEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING & TECHNOLOGY
(AUTONOMOUS)
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Evaluation Procedure for External Laboratory Examinations:

1. For Practical subjects there is a continuous evaluation during the semester for 25 Sessional
marks and 50 end examination marks.
2. The end examination shall be conducted by the teacher concerned (Internal Examiner) and
another External Examiner, recommended by Head of the Department with the approval of
principal.

Evaluation procedure for external lab examination:


1. Procedure for the program----------------------------------------------- 20M
2. Execution of the program------------------------------------------------ 15M
3. Viva voce ------------------------------------------------------------------ 15M

Total 50M

Dr.K. Subba Reddy


Professor & Head Dept. of CSE.

You might also like