Web Technology Lab Manual III I r18
Web Technology Lab Manual III I r18
Web Technology Lab Manual III I r18
MLRITM
WEB TECHNOLOGY
LAB MANUAL
Page 1
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
CERTIFICATE
BRANCH : CSE
REGULATION : R18
Page 2
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Vision:
Mission:
qualities
Education and Research partnership with institutions and industries to prepare the
Page 3
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Vision:
Mission:
Page 4
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Computer Science & Engineering (CSE) is one of the most prominent technical
fields in Engineering. The curriculum offers courses with various areas of
emphasis on theory, design and experimental work. Subject matter ranges from
basics of Computers & Programming Languages to Compiler Design and Cloud
Computing. It maintains strong tie-ups with industry and is dedicated to preparing
students for a career in Web Technologies, Object Oriented Analysis and Design,
Networking & Security, Databases, Data Mining & Data Warehousing and
Software Testing.
PROGRAM OUTCOMES(POs)
Engineering Graduates will be able to:
1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis
of the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
Page 5
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
PSO1: Applications of Computing: Ability to use knowledge in various domains to provide solution to new ideas
and innovations.
PSO2: Programming Skills: Identify required data structures, design suitable algorithms, develop and maintain
software for real world problems
Page 6
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Things to Do:
1) Students should not bring any electronic gadgets into the lab.
2) They should not come late.
3) You should not create any disturbances to others.
Page 7
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Course Outcomes
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools
List of Experiments
1. Implement the data link layer framing methods such as character, character-
stuffing and bit stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and
CRC CCIP
3. Develop a simple data link layer that performs the flow control using the sliding
window protocol, and loss recovery using the Go-Back-N mechanism.
4. Implement Dijsktra’s algorithm to compute the shortest path through a network
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
6. Implement distance vector routing algorithm for obtaining routing tables at each
node.
7. Implement data encryption and data decryption
8. Write a program for congestion control using Leaky bucket algorithm.
9. Write a program for frame sorting technique used in buffers.
10. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
11. How to run Nmap scan
12. Operating System Detection using Nmap
13. Do the following using NS2 Simulator
Page 8
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate& Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of
Packets
Page 9
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
TEXT BOOKS:
1. WEB TECHNOLOGIES: A Computer Science Perspective, Jeffrey C. Jackson,
Pearson Education.
REFERENCES:
1. Deitel H.M. and Deitel P.J., “Internet and World Wide Web How to program”,
Pearson International, 2012, 4th Edition.
2. J2EE: The complete Reference By James Keogh, McGraw-Hill
3. Bai and Ekedhi, The Web Warrior Guide to Web Programming, Thomson
4. Paul Dietel and Harvey Deitel,” Java How to Program”, Prentice Hall of India, 8th
Edition
5. Web technologies, Black Book, Dreamtech press.
6. Gopalan N.P. and Akilandeswari J., “Web Technology”, Prentice Hall of India
Page 10
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
3 Write a PHP script to merge two arrays and sort them as numbers, in
descending order.
Write a PHP script that reads data from one file and write into
4
another file.
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
5
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation
Page 11
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Additional programs
WEB TECHNOLOGIES VIVA QUESTIONS
INDEX
1.1 OBJECTIVE:
1.2 RESOURCES:
1.4 PROCEDURE:
<?php
$num = 1 ;
while ($num < 50 ) {
$count=0;
for ( $i=1;$i<=$num;$i++) {
if (($num%$i)==0) {
$count++;
}
}
if ($count<3) {
echo $num." , ";
} $num=$num+1;
}
?>
Page 12
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
PHP script to
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.
SOURCE CODE:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
Page 13
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<body>
<?php
echo "<br>";
?>
</body>
</html>
OUTPUT:
Page 14
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<?php
// PHP program to count number of words in a string
// Function call
$len = get_num_of_words($str);
OUTPUT:
Page 15
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
SOURCE CODE:
<?php
// PHP program to reverse a string using strrev()
function Reverse($str){
return strrev($str);
}
// Driver Code
$str = "SREYAS";
echo Reverse($str)
?>
OUTPUT:
Page 16
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
SOURCE CODE:
<?php
$word = "Marri Laxman";
$mystring = "MARRI INSTITUTE OF ENGINEERING AND TECHNOLOGY";
OUTPUT:
Page 17
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.
SOURCE CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<title>3. Write a PHP script to merge two arrays and sort them as numbers, in descending
order.</title>
</head>
<body>
//3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.
<?php
echo"<br><br>";
$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);
?>
</body>
</html>
OUTPUT:
Page 18
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
4. Write a PHP script that reads data from one file and write into another file.
SOURCE CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Write a PHP script that reads data from one file and write into another file.</title>
</head>
<body>
//4. Write a PHP script that reads data from one file and write into another file.
<?php
$source='source.txt';
$target='target.txt';
$lines=file( $source );
$data=array();
?>
</body>
</html>
source.txt:
Page 19
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
target.txt:
`````
Page 20
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
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.
i. Home page
ii. Registration and user Login
iii. User Profile Page
iv. Books catalog
v. Shopping Cart
vi. Payment By credit card
vii. Order Conformation.
SOURCE CODE:
i. Home_Page.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="pink"> <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>
OUTPUT:
Page 21
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Reg.html:
<html>
<body bgcolor="pink">
<center>
<h1> <b> <u>STUDENT DETAILS</u></b> </h1>
<form action="insert_form.php" method="post">
Page 22
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Login.html:
<html>
<head>
<title>
Registration and user Login</title>
</head>
<body bgcolor="pink"> <center>
<strong><h1> AMAZON </h1></strong></center>
<table align="center">
<tr>
<td><h4>Enter User name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
<td><h4>Enter Password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
Page 23
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Page 24
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<tr>
<tr>
<td><h4>Edit password</td>
<td><input type="password"></td>
</tr>
<tr>
<option >
<td><h4>male
<input type="radio" name="sex" id="male"></td>
<td><h4>female
<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>
OUTPUT:
Page 25
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>MySQL Server
</td></tr>
<tr>
<td></td>
Page 26
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<td><h4>Mongo DB </td>
</tr> <tr>
<td></td>
<td><h4>PostgreSQL</td>
</tr>
<tr> 9100072127
<td></td>
<td><h4>DB2</td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>
OUTPUT:
v. Shopping Cart:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="pink">
<center><h1>
Page 27
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select name="My_menu" value="My_menu">
</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>
OUTPUT:
Page 28
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<html>
<head><title>payment</title></head>
<body bgcolor="pink">
<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>
<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>
OUTPUT:
Page 29
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="pink">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
OUTPUT:
Page 30
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
6. Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
SOURCE CODE:
Main.html:
<html>
<head>
<title>
Home Page
</title>
</head>
<frameset rows="30%,70%">
<frame src="top.html" name="top">
<frameset cols="30%,70%">
<frame src="left.html" name="left">
<frame src="right.html" name="right">
Page 31
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
</frameset>
</frameset>
</html>
Top.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="pink"> <center>
<strong><h1>Welcome to AMAZON</h1></strong>
<br><br>
<h1 align=”center”><b><u>ONLINE BOOK STORAGE</u></b></h1>
</body>
</html>
Right.html:
<html>
<body bgcolor="pink">
<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:
<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">
Page 32
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
Page 33
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Page 34
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
</script>
<form name="myform">
<div align="center"><pre>
<table align="center" border="1">
<tr>
<td><h4>Enter User name</td>
<td><input type="text" ></td>
</tr>
<tr>
<td><h4>Enter Password</td>
<td><input type="password"></td>
</tr>
OUTPUT:
Page 35
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<body bgcolor="pink"><br><br>
<script language=”javascript”>
function validate()
{
var flag=1;
if(document.myform.name.value==””||
document.myform.addr.value==””||
document.myform.phno.value==””||
document.myform.id.value==””||
document.myform.pwd.value==””)
{
flag=0;
}
var str=document.myform.phno.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}}
</script>
<table align="center"border="1">
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br><br>
ADDRESS :<input type="type" name="addr"><br><br>
CONTACT NUMBER:<input type="text" name="phno"><br><br>
LOGINID :<input type="text" name="id">
<br>
PASS0WORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
Page 36
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<div align="center">
<input 536type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</table>
</body></html>
OUTPUT:
Books catalog :
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
Page 37
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.title.value=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->c"+" cost-->444");
}
else if(str=="jsp")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->jsp"+" cost-->555");
}
else
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" >
<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" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
Page 38
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
</html>
OUTPUT:
Shopping cart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
Page 39
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.title.value==""||
document.myform.no.value==""||
document.myform.cost.value==""||
document.myform.date.value=="")
{
flag=0;
}
var str=document.myform.no.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" >
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
TITLE :<input type="text" name="title"><br>
NO.OF BOOKS:<input type="text" name="no"><br>
Page 40
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
Page 41
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
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;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.num.value;
for(var i=0;i<str.lenght;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
Page 42
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
Order Conformation
Order.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
Page 43
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
OUTPUT:
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.
SOURCE CODE:
import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.Scanner;
Page 44
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
DocumentBuilder b = fac.newDocumentBuilder();
Document doc = b.parse(new File("users.xml"));
doc.getDocumentElement().normalize();
Element root = doc.getDocumentElement();
Scanner in = new Scanner(System.in);
System.out.println("Enter User ID:");
int n = in.nextInt();
int flag = 0;
NodeList nl = doc.getElementsByTagName("user");
for(int i = 0; i < nl.getLength(); i++)
{
Node node = nl.item(i);
if(node.getNodeType() == Node.ELEMENT_NODE)
{
Element e = (Element) node;
int x =
Integer.parseInt(e.getElementsByTagName("userid").item(0).getTextcontent());
if(x==n)
{
System.out.println(root.getNodeName());
System.out.println("============================================");
System.out.println("User id :" +
e.getElementsByTagName("userid").item(0).getTextcontent());
System.out.println("Adress :" +
e.getElementsByTagName("address").item(0).getTextcontent());
System.out.println("Gender :" +
e.getElementsByTagName("Gender").item(0).getTextcontent());
flag=1;
break;
}
else
{
flag=0;
}
}
}
if(flag==0)
System.out.println("User Id is not present.Try Again!!!");
}
Page 45
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
users.xml:
<users-details>
<user>
<userid>1111</userid>
<name>Sammulal</name>
<address>Hyderabad</address>
<gender>Male</gender>
</user>
<user>
<userid>1112</userid>
<name>Sanjana</name>
<address>Banglore</address>
<gender>Female</gender>
</user>
<user>
<userid>1113</userid>
<name>kishor</name>
<address>karimnagar</address>
<gender>Male</gender>
</user>
<user>
<userid>1114</userid>
<name>Srindhar</name>
<address>USA</address>
<gender>Male</gender>
</user>
<user>
<userid>1115</userid>
<name>Rajitha</name>
<address>Hyderbad</address>
<gender>Female</gender>
</user>
<user>
<userid>1116</userid>
<name>Aradhya</name>
<address>Hyderabad</address>
<gender>Female</gender>
</user>
<user>
<userid>1117</userid>
<name>Vikram</name>
<address>Ludan</address>
Page 46
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<gender>Male</gender>
</user>
<user>
<userid>1118</userid>
<name>SaiKrishna</name>
<address>Pune</address>
<gender>Male</gender>
</user>
<user>
<userid>1119</userid>
<name>Deeksha</name>
<address>NewYork</address>
<gender>Female</gender>
</user>
<user>
<userid>1120</userid>
<name>Charan</name>
<address>Chennai</address>
<gender>Male</gender>
</user>
</users-details>
OUTPUT:
D:\madhucse\labprograms>javac Exp5aDOMParser.java
D:\madhucse\labprograms>java Exp5aDOMParser
Enter User ID:
1111
users-details
============================================
User id :1111
User Name :Sammulal
Adress :Hyderabad
Gender :Male
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.
PROCEDURE:
1. First install the tomcat into the system.
2. Then make a subdirectly(eg., tr) in the \tomcat\webapps.
3. Under tr create WEB-INF directory and also place the html files in this tr directory only.
Page 47
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Step 1:
Installation of JDK:
Before beginning the process of installing Tomcat on your system, ensure first the
availability of JDK on your system program directory. Install it on your system if not already
installed (because any version of tomcat requires the Java 1.6 or higher versions) and then set the
class path (environment variable) of JDK. To set the JAVA_HOME Variable: you need to
specify the location of the java run time environment to support the Tomcat else Tomcat server
can not run.
Note: it should not contain the path up to bin folder. Here, we have taken the URL path
according to our installation convention.
Now click on all the subsequent ok buttons one by one. It will set the JDK path.
Step 2:
For setting the class path variable for JDK, do like this:
Page 48
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OR
My Computer->properties->advance->Environment Variables->path.
Step 3:
The process of installing Tomcat 6.0 begins here from now. It takes various steps for installing
and configuring the Tomcat 6.0.
For Windows OS, Tomcat comes in two forms: .zip file and .exe file (the Windows
installer file). Here we are exploring the installation process by using the .exe file. First unpack
the zipped file and simply execute the '.exe' file.
A Welcome screen shot appears that shows the beginning of installation process. Just click on
the 'Next' button to proceed the installation process.
Page 49
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Page 50
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Step 6:
A screen shot of 'Configuration Options' displays on the screen. Choose the location for
the Tomcat files as per your convenience. You can also opt the default Location
The port number will be your choice on which you want to run the tomcat server. The port
number 8080 is the default port value for tomcat server to proceed the HTTP requests. The user
can also change the 'port number' after completing the process of installation; for this, users have
to follow the following tips.
Go to the specified location as " Tomcat 6.0 \conf \server.xml ". Within the server.xml file
choose "Connector" tag and change the port number.
Now, click on the 'Next' button to further proceed the installation process.
This window asks for the location of the installed Java Virtual Machine. Browse the location of
the JRE folder and click on the Install button. This will install the Apache tomcat at the specified
location.
Page 51
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Step 8:
To get the information about installer click on the "Show details" button
Step 9:
Step 10:
A window of Apache Service Manager appears with displaying the running process.
Page 52
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Step 11:
After completing the installation process, the Apache Tomcat Manager appears on the
toolbar panel like shown in the below picture.
To Configure the Tomcat Manager, there are two ways; either user can configure Tomcat
directly from the toolbar panel or can configure it from Control Panel Section.
Page 53
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
A configured window appears on the desktop. Now, just click on the Startup button. The
installation process will be completed.
Double click on the Apache Tomcat. The window of Apache Tomcat Properties appears on the
screen.
Now, Click on the start up button. The Apache Tomcat is now ready to function.
1. Start the tomcat server from the bin folder of Tomcat 6.0 directory by double clicking the
"tomcat6.exe" file.
OR create a shortcut of this .exe file at your desktop.
Page 54
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
2. 2. Now Open web browser and type URL http://localhost:8080 in the address bar to test
the server.
3. 3. To Stop the Tomcat Server: Stop the server by pressing the "Ctrl + c" keys.
Home page:
Main.html:
<html>
<body>
<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
Page 55
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
</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 page:
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="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()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Registration page:
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg">
<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>
Page 56
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to
RETRY</a>");
}
else
{
pw.println("<br><br>VALID LOGIN ID<br><br>"); 58
pw.println("<h3><ul>");
pw.println("<li><a
href=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font>
</a></li><br><br>");
pw.println("<li><a
href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
pw.println("<li><a
href=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font>
</a></li></ul><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Registration servlet:
Reg.java :
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
resp.setContentType("text/html");
pw.println("<html><body>");
String name=req.getParameter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id1=req.getParameter("id");
String pwd1=req.getParameter("pwd");
Page 59
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
int no=Integer.parseInt(phno);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
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)
{
pw.println("<br><br>SORRY INVALID ID ALREADY
EXITS TRY AGAIN WITH NEW ID<br><br>");
pw.println("<a href=\"reg.html\">press REGISTER to
RETRY</a>");
}
else
{
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"')
;");
pw.println("<br><br>YOUR DETAILS ARE
ENTERED<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to
login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Profile servlet:
Profile.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Page 60
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String title=req.getParameter("title");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'"; ResultSet
rs=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("<br><br>SORRY INVALID TITLE TRY
AGAIN <br><br>");
pw.println("<a href=\"catalog.html\">press HERE to
RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order servlet:
Order.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
Page 62
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Page 63
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>/profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>/order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>main.html</welcome-file></welcome-file-list>
</web-app>
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.
PROCEDURE:
1) Create your own directory under tomcat/webapps (e.g. tr1)
2) Copy the html files in tr1
3) Copy the jsp files also into tr1
4) Start tomcat give the following command
Catalina.bat run
At install-dir/bin
5) at I.E give url as http://localhost:8081/tr1/main.html
Home page:
Main.html:
<html>
<body>
<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="login.html">LOGIN</a>
<a href="reg.html">REGISTRATION</a></div></pre>
</body></html>
Login page:
Login.html:
<html>
<body><br /><br /><br />
Page 65
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile.jsp">
<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()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
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"/>
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body> </html>
Shopping cart, Payment by credit card, Order
Conformation page:
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 />
Page 67
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<div align="center">
<input type="submit" value="ok" name="button1"/>
<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>
Login JSP:
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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); 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)
{
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>");
}
Page 68
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
out.println("</body></html>");
con.close();
%>
Registration JSP:
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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); 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>");
}
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"');"); 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();
Page 69
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
%>
Profile JSP:
Profile.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); 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(1)+"<br>");
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("<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(); %>
Catalog JSP:
Catalog.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String title=request.getParameter("title");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); 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
Page 70
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
:"+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 servlet:
Order.java:
<%@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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); 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)
{
Page 71
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Output:
Page 72
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
TO CREATE TIMETABLE:
<html>
<body>
<table>
<tr>
<th>DAY</th>
<th>1</th>
<th>2</th>
<th></th>
<th>3</th>
<th>4</th>
<th></th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
<tr>
<th>TIME</th>
Page 73
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<th>9:00-10:00</th>
<th>10:00-10:50</th>
<th>10:50-11:00</th>
<th>11:00-11:50</th>
<th>11:50-12:40</th>
<th>12:40-1:20</th>
<th>1:20-2:15</th>
<th>2:15-3:10</th>
<th>3:10-4:00</th>
</tr>
<tr>
<th>MONDAY</th>
<td>CD</td>
<td>NS</td>
<th rowspan=6>BREAK</th>
<td>WT</td>
<td>SEMINAR</td>
<th rowspan=6>LUNCH</th>
<td>VLSI</td>
<td>VLSI</td>
<td>MEFA</td>
</tr>
<tr>
<th>TUESDAY</th>
<td>NS</td>
<td>OOAD</td>
<td>VLSI</td>
Page 74
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<td>MEFA</td>
<td>CD&WT</td>
<td colspan=2>CD&WT</td>
</tr>
<tr>
<th>WEDNESDAY</th>
<td>MEFA</td>
<td>CD</td>
<td>OOAD</td>
<td>WT</td>
<td>NS</td>
<td colspan=2>SPORTS</td>
</tr>
<tr>
<th>THURSDAY</th>
<td>NS</td>
<td>WT</td>
<td>OOAD</td>
<td>CD</td>
</tr>
<tr>
<th>FRIDAY</th>
<td>WT</td>
<td>SEMINAR</td>
<td>CD</td>
<td>NS</td>
Page 75
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<td>MEFA</td>
<td>OOAD</td>
<td>VLSI</td>
</tr>
<tr>
<th>SATURDAY</th>
<td>CD</td>
<td>VLSI</td>
<td>NS</td>
<td>VLSI</td>
<td>WT</td>
<td>LIB</td>
<td>OOAD</td>
</tr>
<img style="position:absolute;z-index:-1"src="C:\Users\Public\Pictures\Sample
Pictures\tulips.jpg" height="500" width="1500">
</body>
</html>
Page 76
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<html>
<head>
<title>
Registration Form
</title>
</head>
<body bgcolor="pink">
<form name="regform">
<h2>Registration Form</h2>
Page 77
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
<h4>Select Gender:</h4>
<h4>Nationality:</h4>
<option value="My_menu">select</option>
<option value="Hindu">Hindu</option>
<option value="Christian">Christian</option>
<option value="Muslim">Muslim</option>
<option value="Others">Others</option>
</select><br><br>
</form>
</body>
</html>
Page 78
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
OUTPUT:
Page 79
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
TO CREATE FRAMES:
<html>
<head>
<title>
Home Page
</title>
</head>
<frameset rows="30%,70%">
<frame src="title.html" name="name1">
<frameset cols="30%,70%">
<frame src="menu.html" name="name2">
<frame src="home.html" name="name3">
</frameset>
</frameset>
</html>
OUTPUT:
HTML
1. What is HTML?
2. What is a tag?
In HTML, a tag tells the browser what to do. When you write an HTML page, you enter
tags for many reasons; to change the appearance of text, to show a graphic, or to make a
link to another page.
HTML Code:
Page 80
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Frames allow an author to divide a browser window into multiple (rectangular) regions.
Multiple documents can be displayed in a single window, each within its own frame.
Graphical browsers allow these frames to be scrolled independently of each other, and
links can update the document displayed in one frame without affecting the others.
You can’t just “add frames” to an existing document. Rather, you must create a frameset
document that defines a particular combination of frames, and then display your content
documents inside those frames. The frameset document should also include alternative
non-framed content in a NOFRAMES element.
An HTML comment begins with “<!—“, ends with “--> “, and does not contain “--“ or
“>” anywhere in the comment.
A hypertext link is a special tag that links one page to another page or resource. If you
click the link, the browser jumps to the link’s destination.
Yes, a table can be embedded inside a cell in another table. The main caveat about nested
tables is that older versions of Netscape Navigator have problems with them if you don’t
Page 81
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
explicitly close you TR, TD, and TH elements. To avoid problems, include closing tags
for you TR, TD, an TH even though the HTML specifications don’t require them.
You use the <table align=”right”> property to float a table to the right. Put left in place of
right to float right.
Small forms are sometimes placed within a TD element within a table. This can be useful
for positioning a form relative to other content, but it doesn’t help position the form-
related elements relative to each other. The table must be within the form and then use
the table to position the form elements.
JavaScript:
ECMAScript is yet another name for JavaScript (other names include LiveScript). The
current JavaScript that you see supported in browsers is ECMAScript revision
Use the parseInt() function, that takes a string as the first parameter, and the base as a second
parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16).
Page 82
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
&&, || and !
Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so
78 is the result.
arr[arr.length] = value;
HTML authors are normally not programmers, but JavaScript is a scripting language with a
very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages
A JavaScript can be set to execute when something happens, like when a page has finished
loading or when a user clicks on an HTML element.
A JavaScript can be used to validate form data before it is submitted to a server. This saves
the server from extra processing
Page 83
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
A JavaScript can be used to detect the visitor's browser, and - depending on the browser -
load another page specifically designed for that browser.
19. JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve
information on the visitor's computer
Called (CSS) is a list of statements (or rules) that can assign various rendering properties to
HTML elements. Style rules can be specified for a single element occurrence, multiple
elements, and entire document, or even multiple documents at once.
2. What is class?
A group of instances of the same element to which a unique style can be attached.
3. What is grouping?
Gathering into a comma separated list two or more selectors that share the same style or
into a semicolon separated list two or more declarations that are attached to the same
selector.
4. What is ID selector?
Page 84
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
CSS allows Unicode characters to be entered by number. For example, if a class value in
some Russian document contains Cyrillic letters EL PE (Unicode numbers 041B and 041F)
and you want to write a style rule for that class, you can put that letter into the style sheet
by writing:
This works on all keyboards, so you don’t need a Cyrillic keyboard to write class names in
Russian or another language that uses that script.
Classes can be created for use on multiple tag types in the document.
Selector and grouping methods can be used to apply styles under complex contexts
No additional downloads necessary to receive style information.
Page 85
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Property is a stylistic parameter (attribute) that can be influenced through CSS, e.g. font or
width. There must always be a corresponding value or values set to each property.
The clear property specifies which sides of an element where other floating elements
are not allowed.
What is XML?
XML tags are not predefined. You must define your own tags
Page 86
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
XML was designed to transport and store data, with focus on what data is
HTML was designed to display data, with focus on how data looks
Servlets:
Page 87
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
The servlet is removed from service, destroyed with the destroy() methid, then garbaged
collected and finalized.
A: Cookies
SSL sessions
Page 88
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
URL- rewriting
Q: Explain ServletContext.
A: ServletContext interface is a window for a servlet to view it's environment. A servlet can
use this interface to get information such as initialization parameters for the web
applicationor servlet container's version. Every web application has one and only one
ServletContext and is accessible to all active resource of that application.
A: A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when
it receives a request for that servlet first time. This is called lazy loading. The servlet
specification defines the <load-on-startup> element, which can be specified in the
deployment descriptor to make the servlet container load and initialize the servlet as soon as
it starts up. The process of loading a servlet before any request comes in is called
preloading or preinitializing a servlet.
A: A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have
this limitation. A request string for doGet() looks like the following:
http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
doPost() method call doesn't need a long text tail after a servlet name in a request. All
parameters are stored in a request itself, not in a request string, and it's impossible to guess
the data transmitted to a servlet only looking at a request string.
A: ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet
container, for example, to get the MIME type of a file, dispatch requests, or write to a log
file.The ServletContext object is contained within the ServletConfig object, which the Web
server provides the servlet when the servlet is initialized
Page 89
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
ServletConfig: The object created after a servlet is instantiated and its default constructor is
read. It is created to pass initialization information to the servlet.
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the
only supported protocol in JSP is HTTP. But a servlet can support any protocol like
HTTP, FTP, SMTP etc.
Page 90
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session
information
5. Difference between GET and POST
In GET your entire form submission can be encapsulated in one URL, like a hyperlink.
query length is limited to 255 characters, not secure, faster, quick and easy. The data is
submitted as part of URL.
In POST data is submitted inside body of the HTTP request. The data is not visible on
the URL and it is more secure.
6. What is session?
The session is an object used by a servlet to track a user’s interaction with a Web
application across multiple HTTP requests. The session is stored on the server.
7. What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The
mapping is used to map requests to Servlets.
8. What is servlet context ?
The servlet context is an object that contains a information about the Web application and
container. Using the context, a servlet can log events, obtain URL references to
resources, and set and store attributes that other servlets in the context can use.
9. What is a servlet ?
servlet is a java program that runs inside a web container.
10. Can we use the constructor, instead of init(), to initialize servlet?
Yes. But you will not get the servlet specific things from constructor. The original reason
for init() was that ancient versions of Java couldn’t dynamically invoke constructors with
arguments, so there was no way to give the constructor a ServletConfig. That no longer
applies, but servlet containers still will only call your no-arg constructor. So you won’t
have access to a ServletConfig or ServletContext.
2. How many JSP scripting elements are there and what are they?
Static resources should always be included using the JSP include directive. This way, the
inclusion is performed just once during the translation phase
4. How can I implement a thread-safe JSP page?
Page 91
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
You can make your JSPs thread-safe adding the directive <%@ page
isThreadSafe="false" % > within your JSP page.
Page 92
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
A scriptlet can contain any number of language statements, variable or expressions that
are valid in the page scripting language. Within scriptlet tags, you can declare variables to
use later in the file, write expressions valid in the page scripting language, use any of the
JSP implicit objects or any object declared with a . Generally a scriptlet can contain any
java code that are valid inside a normal java method. This will become the part of
generated servlet’s service method.
1. What is a servlet?
Servlets are modules that extend request/response-oriented servers,such as Java-enabled
web servers. For example, a servlet might be responsible for taking data in an HTML
order-entry form and applying the business logic used to update a company’s order
database. Servlets are to servers what applets are to browsers. Unlike applets, however,
servlets have no graphical user interface.
2. Whats the advantages using servlets over using CGI?
Servlets provide a way to generate dynamic documents that is both easier to write and
faster to run. Servlets also address the problem of doing server-side programming with
platform-specific APIs: they are developed with the Java Servlet API, a standard Java
extension.
A servlet can handle multiple requests concurrently, and synchronize requests. This
allows servlets to support systems such as online
real-time conferencing. Servlets can forward requests to other servers and servlets. Thus
servlets can be used to balance load among several servers that mirror the same content,
and to partition a single logical service over several servers, according to task type or
organizational boundaries.
javax
The central abstraction in the Servlet API is the Servlet interface. All servlets implement
this interface, either directly or, more commonly, by extending a class that implements it
Page 93
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
6. When a servlet accepts a call from a client, it receives two objects. What are they?
ServletRequest (which encapsulates the communication from the client to the server) and
ServletResponse (which encapsulates the communication from the servlet back to the
client). ServletRequest and ServletResponse are interfaces defined inside javax.servlet
package.
Information such as the names of the parameters passed in by the client, the protocol
(scheme) being used by the client, and the names
of the remote host that made the request and the server that received it. Also the input
stream, as ServletInputStream.Servlets use the input stream to get data from clients that
use application protocols such as the HTTP POST and GET methods.
It can set the content length and MIME type of the reply. It also provides an output
stream, ServletOutputStream and a Writer through
which the servlet can send the reply data.
Each servlet has the same life cycle: first, the server loads and initializes the servlet
(init()), then the servlet handles zero or more client requests (service()), after that the
server removes the servlet (destroy()). Worth noting that the last step on some servers is
done when they shut down.
An HTTP Servlet handles client requests through its service method. The service method
supports standard HTTP client requests by dispatching each request to a method designed
to handle that request.
Page 94
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
This action involves two steps: loading the JDBC driver and making the connection.
Loading the driver or drivers you want to use is very simple and involves just one line of
code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code
will load it:
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
Your driver documentation will give you the class name to use. For instance, if the class
name is jdbc.DriverXYZ, you would load the driver with the following line of code:
Class.forName(”jdbc.DriverXYZ”);
To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:
5. How can you create JDBC statements and what are they?
A Statement object is what sends your SQL statement to the DBMS. You simply create a
Statement object and then execute it, supplying the appropriate execute method with the
SQL statement you want to send. For a SELECT statement, the method to use is
executeQuery. For statements that create or modify tables, the method to use is
Page 95
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
JDBC returns results in a ResultSet object, so we need to declare an instance of the class
ResultSet to hold our results. The following code demonstrates declaring the ResultSet
object rs.
The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get)
the value stored in the column COF_NAME in the current row of rs.
This special type of statement is derived from class Statement.If you need a Statement
object to execute many times, it will normally make sense to use a PreparedStatement object
instead. The advantage to this is that in most cases, this SQL statement will be sent to the
DBMS right away, where it will be compiled. As a result, the PreparedStatement object
contains not just an SQL statement, but an SQL statement that has been precompiled. This
means that when the PreparedStatement is executed, the DBMS can just run the
PreparedStatement’s SQL statement without having to compile it first.
Page 96
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
is executed. The way to allow two or more statements to be grouped into a transaction is to
disable auto-commit mode:
11. How do you call a stored procedure from JDBC?
The first step is to create a CallableStatement object. As with Statement an and
PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.
JSP is a technology that combines HTML/XML markup languages and elements of Java
programming Language to return dynamic content to the Web client, It is normally used to
handle Presentation logic of a web application, although it may have business logic.
JSP page looks like a HTML page but is a servlet. When presented with JSP page the JSP
engine does the following 7 phases.
A. Page translation: -page is parsed, and a java file which is a servlet is created.
Page 97
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
JSP page can include the contents of other HTML pages or other JSP files. This is done
by using the include directive. When the JSP engine is presented with such a JSP page it
is converted to one servlet class and this is called a translation unit, Things to remember
in a translation unit is that page directives affect the whole unit, one variable declaration
cannot occur in the same unit more than once, the standard action jsp:useBean cannot
declare the same bean twice in one unit.
Page 98
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
number of variables or methods within one declaration tag, as long as semicolons separate
them. The declaration must be valid in the scripting language used in the JSP file.
9. What is a Scriptlet?
A scriptlet can contain any number of language statements, variable or method declarations,
or expressions that are valid in the page scripting language. Within scriptlet tags, you can
declare variables or methods to use later in the file, write expressions valid in the page
scripting language, use any of the JSP implicit objects or any object declared with a
<jsp:useBean>.
10. What are the implicit objects? List them.
Certain objects that are available for the use in JSP documents without being declared first.
These objects are parsed by the JSP engine and inserted into the generated servlet. The
implicit objects are:
request
response
pageContext
session
application
out
config
page
exception
11. What’s the difference between forward and sendRedirect?
When you invoke a forward request, the request is sent to another resource on the server,
without the client being informed that a different resource is going to process the request.
This process occurs completely with in the web container And then returns to the calling
method. When a sendRedirect method is invoked, it causes the web container to return to
the browser indicating that a new URL should be requested. Because the browser issues a
completely new request any object that are stored as request attributes before the redirect
occurs will be lost. This extra round trip a redirect is slower than forward.
12. What are the different scope values for the <jsp:useBean>?
The different scope values for <jsp:useBean> are:
page
Page 99
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
request
session
application
13. Why are JSP pages the preferred API for creating a web-based client program?
Because no plug-ins or security policy files are needed on the client systems(applet does).
Also, JSP pages enable cleaner and more module application design because they provide a
way to separate applications programming from web page design. This means personnel
involved in web page design do not need to understand Java programming language syntax
to do their jobs.
14. Is JSP technology extensible?
Yes, it is. JSP technology is extensible through the development of custom actions, or tags,
which are encapsulated in tag libraries.
15. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are
interpreted, and then group your tags into collections called tag libraries that can be used in
any number of JSP files. Custom tags and beans accomplish the same goals —
encapsulating complex behavior into simple and accessible forms. There are several
differences:
Custom tags can manipulate JSP content; beans cannot.
Complex operations can be reduced to a significantly simpler form with custom
tags than with beans.
Custom tags require quite a bit more work to set up than do beans.
Custom tags usually define relatively self-contained behavior, whereas beans are
often defined in one servlet and used in a different servlet or JSP page.
Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP
1.x versions.
The javax.servlet package defines the contract between container and the servlet class. It
provides the flexibility to container vendor to implement the API the way they want so
long as they follow the specification. To the developers, it provides the library to develop
the servlet based applications.
Interfaces of javax.Servlet
Page 100
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM
Page 101