Web Technology Lab Manual III I r18

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 101

COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL

MLRITM

WEB TECHNOLOGY
LAB MANUAL

III-B Tech – I Semester

MARRI LAXMAN REDDY INSTITUTE OF TECHNOLOGY AND


MANAGEMENT
(Approved by AICTE, Affiliated to JNTUH)
Dundigal, Hyderabad

Page 1
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

CERTIFICATE

LAB NAME : WEB TECHNOLOGIES LAB

BRANCH : CSE

YEAR & SEM : III – I

REGULATION : R18

Page 2
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

VISION & MISSION OF INSTITUTION

Vision:

To be as an ideal academic institution by graduating talented engineers to be

ethically strong, competent with quality research and technologies.

Mission:

 Utilize rigorous educational experiences to produce talented engineers

 Create an atmosphere that facilitates the success of students

 Programs that integrate global awareness, communication skills and Leadership

qualities

 Education and Research partnership with institutions and industries to prepare the

students for interdisciplinary research

Page 3
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

VISION & MISSION OF DEPARTMENT

Vision:

To empower the students to be technologically adept, innovative, self-


motivated and responsible global citizen possessing human values and
contribute significantly towards high quality technical education with ever
changing world.

Mission:

 To offer high-quality education in the computing fields by providing an


environment where the knowledge is gained and applied to participate in
research, for both students and faculty.
 To develop the problem solving skills in the students to be ready to deal with
cutting edge technologies of the industry.
 To make the students and faculty excel in their professional fields by
inculcating the communication skills, leadership skills, team building skills
with the organization of various co-curricular and extra-curricular
programmes.
 To provide the students with theoretical and applied knowledge, and adopt
an education approach that promotes lifelong learning and ethical growth.

Page 4
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

Program Educational Objectives

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.

PROGRAM SPECIFIC OUTCOMES (PSOs)

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

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


III Year B.Tech CSE- II Sem

WEB TECHNOLOGIES LAB INSTRUCTIONS TO THE STUDENTS

Things to Do:

1) Students should come in formal dresses.


2) Students must wear their id cards.
3) They have to be in the lab before 10 minutes.
4) They should come up with the observation and the record.
5) Observation should get corrected with the concerned faculty.
6) The programs corrected by the faculty have to copy to record.
7) They should maintain silence in the lab.

Things not 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.

HOD Lab Incharge

Page 7
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD 


III Year B.Tech. CSE. I – Sem L  T P  C 
Course Code: CS605PC 3    0 0  3 

COMPUTER NETWORKS & WEB TECHNOLOGIES LAB


Course Objectives
1. To understand the working principle of various communication protocols.
2. To understand the network simulator environment and visualize a network
topology and observe its performance
3. To analyze the traffic flow and the contents of protocol frames

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

Web Technologies Experiments


1. Write a PHP script to print prime numbers between 1-50.
2. 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.
3. Write a PHP script to merge two arrays and sort them as numbers, in descending
order.
4. Write a PHP script that reads data from one file and write into another file.
5. Develop static pages (using Only HTML) of an online book store. The pages
should resemble: www.amazon.com. The website should consist the following
pages.
a) Home page
b) Registration and user Login
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation
6. Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
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.
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.
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.

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

Web Technologies Experiments


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

3 Write a PHP script to merge two arrays and sort them 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

Validate the Registration, user login, user profile and payment by


6 credit card pages using JavaScript.

Create and save an XML document on the server, which contains 10


7 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.
Install TOMCAT web server. Convert the static web pages of
assignments 2 into dynamic web pages using servlets and cookies.
8 Hint: Users information (user id, password, credit card number) 123-140
would be stored in web.xml. Each user should have a separate
Shopping Cart.
Redo the previous task using JSP by converting the static web pages
of assignments 2 into dynamic web pages. Create a database with user
9 information and books information. The books catalogue should be
dynamically loaded from the database. Follow the MVC architecture
while doing the website.

Page 11
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

Additional programs
WEB TECHNOLOGIES VIVA QUESTIONS
INDEX

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

1.1 OBJECTIVE:

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

1.2 RESOURCES:

NOTEPAD++, 1GB RAM, Hard Disk 80 GB

1.3 PROGRAM LOGIC:

1. Create a PHP file.


2. Read a number in one text field and display that number name in another text field.
3. Include the JavaScript to convert number into words.

1.4 PROCEDURE:

To execute a html program:


1. Open Notepad++ and Save the PHP program in “SREYAS” folder in drive.
3. To run the html file open the browser and type the following URL directory name/filename.

1.5 SOURCE CODE:

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

WEEK-2: PHP script to

Find the length of a string.


a.
b. Count no of words in a string.
c. Reverse a string.
d. Search for a specific string.
2.1 OBJECTIVE:

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.

a). Find the length of a string.

SOURCE CODE:

<!DOCTYPE html>

<html lang="en">

<head>

<title>Example of Obtaining String Length in PHP</title>

</head>

Page 13
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

<body>

<?php

$str1 = 'Hello world!';

echo 'Length of $str1 is - ' . strlen($str1);

echo "<br>";

$str2 = ' Hello world! ';

echo 'Length of $str2 is - ' . strlen($str2);

?>

</body>

</html>

OUTPUT:

Page 14
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

b). Count no of words in a string.

<?php
// PHP program to count number of words in a string

// Function to count the words


function get_num_of_words($string) {
$string = preg_replace('/\s+/', ' ', trim($string));
$words = explode(" ", $string);
return count($words);
}

$str = " MARRI INSTITUTE OF ENGINEERING AND TECHNOLOGY";

// Function call
$len = get_num_of_words($str);

// Printing the result


echo $len;
?>

OUTPUT:

Page 15
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

c). Reverse a string.

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

d). Search for a specific string.

SOURCE CODE:

<?php
$word = "Marri Laxman";
$mystring = "MARRI INSTITUTE OF ENGINEERING AND TECHNOLOGY";

// Test if string contains the word


if(strpos($mystring, $word) !== false){
echo "Word Found!";
} else{
echo "Word Not Found!";
}
?>

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

foreach( $lines as $line ){


/* store each line with a leading zero into a temp array */
$data[]='0' . trim( $line );
}

/* write the content back to another file */


file_put_contents( $target, implode( PHP_EOL, $data ) );

?>

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

ii. Registration and user Login:

Reg.html:
<html>
<body bgcolor="pink">
<center>
<h1> <b> <u>STUDENT DETAILS</u></b> </h1>
<form action="insert_form.php" method="post">

Enter Rollno: <input type="text" name="rollno"><br/><br/>


Enter User Name: <input type="text" name="name"><br/><br/>
Enter Password: <input type="password" name="password"><br/><br/>
Enter MobileNo: <input type="text" name="mobile_no"><br/><br/><br/>

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


<input type="reset" value="clear">
</form>
</center>
</body>
</html>
OUTPUT:

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

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


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

iii. User Profile Page


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

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 &nbsp;&nbsp;
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Edit Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
</tr>
</form>
</body>
</html>

OUTPUT:

Page 25
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

iv. Books catalog:


<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="pink">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>JAVA</td>
</tr>
<tr>
<td></td>
<td><h4>Computer Networks</td>
</tr>
<tr>
<td></td>
<td><h4>Software Engineering
</td></tr>
<tr>
<td></td>
<td><h4>Compiler Design
</td></tr>

<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>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">

<option value="select">select the book


<option value="JAVA">JAVA
<option value="Computer Networks">Computer Networks
<option value="Software Engineering">Software Engineering
<option value="Compiler Design">Compiler Design
<option value="Oracle">Oracle
<option value="MySQL Server">MySQL Server
<option value="Mongo DB">Mongo DB
<option value="PostgreSQL">PostgreSQL
<option value="DB2">DB2

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

vi. Payment By credit card:

<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

vii. Order Conformation:

<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

<font color=”black”> BOOKS CATALOG</font>


</a>
</li>
<br><br>
<li>
<a href="scart.html" target="right">
<font color=”black”> SHOPPINGCART</font>
</a>
</li><br>
<br>
<li>
<a href="payment.html" target="right">
<font color=”black”> PAYMENT</font>
</a>
</li><br><br>
<li>
<a href="order.html" target="right">
<font color=”black”> ORDER CONFIRMATION</font>
</a>
</li><br><br>
</ul>
</body>
</html>

OUTPUT:

Page 33
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

Registration and user Login


Login.html:
<html>
<head>
<title>
User Login</title>
</head>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.pwd.value=="")
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}

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>

<tr colspan="2" align="center">


<td >

<input type="submit" value="SUBMIT" onClick="validate()">


&nbsp;&nbsp;
<input type="reset" value="reset">
</td>
</tr>
</table>
</form>
</body>
</html>

OUTPUT:

User profile page


Profile.html:
<html>

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()">&nbsp;&nbsp;&nbsp;
<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()">&nbsp;&nbsp;&nbsp;&nbsp;
<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

COST OF BOOK:<input type="text"name="cost"><br>


DATE :<input type="text" name="date"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</form>
</body>
</html>

OUTPUT:

Payment by credit card


Payment.html:

<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

PASSWORD :<input type="password" name="pwd">


<br>
AMOUNT :<input type="text" name="amount"><br>
CREDITCARDNUMBER:<input
type="PASSWORD"
name="num+"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</form>
</body>
</html>

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

public class Exp5aDOMParser{


public static void main(String[] args) throws Exception {

DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();

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("User Name :" +


e.getElementsByTagName("name").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

4. Next under WEB-INF create two subclasses lib,classes and web.xml


5. Next place all the class files under the classes and jar files(servlet-api.jar,classes12.jar
etc…) under lib
6. subdirectories.
7. After this start tomcat by giving the following command at the instll_dir>tomcat>bin
Catalina.bat run
8. At the I.E(web browser) give the url as http;//localhost:8080//tr/htmlfile or servlet url
pattern
9. Portno 8080 is assigned for the tomcat.

APACHE TOMCAT INSTALLATION

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. 

This variable contains the path of JDK installation directory. 

set JAVA_HOME=C:\Program Files\Java\jdk1.6

Note: it should not contain the path up to bin folder. Here, we have taken the URL path
according to our installation convention. 

For Windows OS, go through the following steps:

Start menu->Control Panel->System->Advanced tab->Environment Variables->New->set


the Variable name = JAVA_HOME and variable value = C:\Program Files\Java\jdk1.6 

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

Start menu->Control Panel->System->Advanced tab->Environment Variables->New->


Set PATH="C:\Program Files\Java\jdk1.6\bin"; %PATH%

OR 

First, right click on the 

My Computer->properties->advance->Environment Variables->path.

Now, set bin directory path of JDK in the path variable

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.

Steps 4:  A screen of 'License Agreement' displays. 

Page 49
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

Click on the 'I Agree' button. 

Step 5: A screen shot appears asking for the 'installing location'

Choose the default components and click on the 'Next' button.  

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. 

Step 7: A Window of Java Virtual Machine displays on the screen

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:

A processing window of installing displays on the screen.

To get the information about installer click on the "Show details" button

Step 9:

A screen shot of 'Tomcat Completion' displays on the screen.

Click on the 'Finish' button. 

Step 10:

A window of Apache Service Manager appears with displaying the running process.

Page 52
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

Let the running process goes on. 

Step 11:
After completing the installation process, the Apache Tomcat Manager appears on the
toolbar panel like shown in the below picture.

Configuring Tomcat Manager

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.

i-) Configuring from toolbar Panel


To Configure Apache Tomcat web server from the toolbar panel, you have to press 'double click'
on the appeared icon.

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. 

To operate it, follow the below steps of processing.

Start the Tomcat Server:

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.

The screen of Apache Tomcat software looks like this:

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()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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

<td>:<input type="password" name="pwd" /></td>


</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
Profile.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
Catalog.html:
<html>
<body><br /><br /><br />
<form method="post" action="catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body>
</html>
Shopping cart, Payment by credit card, Order
Conformation page:
Order.html:
<html>
<body><br /><br />
Page 57
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

<form method="post" action="order">


<div align="center"><pre>
ID
:<input type="text" name="id" /><br />
PASSWORD
:<input type="password" name="pwd" /><br/> TITLE
:<input type="text" name="title" /><br /> NO. OF BOOKS
:<input type="text" name="no" /><br />
DATE
:<input type="text" name="date" /><br />
CREDIT CARD NUMBER :<input type="password" name="cno" /><br /></pre><br
/><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form></body></html>
Login servlet :
Login.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
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(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
Page 58
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 class profile extends HttpServlet


{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
try
{
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;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME :"+rs.getString(1)+"<br>");
pw.println("ADDRESS
:"+rs.getString(2)+"<br>");
pw.println("PHONE NO
:"+rs.getString(3)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href=\"profile.html\">press HERE to
RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Catalog servlet:
Catalog.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
Page 61
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

public void service(HttpServletRequest req,HttpServletResponse resp)


throws ServletException,IOException
{
int count;
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String title=req.getParameter("title");
String count1=req.getParameter("no");
String date=req.getParameter("date");
String cno=req.getParameter("cno");
try
{
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)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href= \" order.html \" >press HERE to RETRY</a>");
}
else
{
Statement stmt2=con.createStatement();
String s="select cost from book where title=\'"+title+"\'"; ResultSet rs1=stmt2.executeQuery(s);
int flag1=0;
while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(1));
amount=count*x;
pw.println("<br><br>AMOUNT
:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details

Page 63
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

values('"+id+"','"+title+"',"+amount+",'"+cno+"');"); pw.println("<br>YOUR ORDER has


taken<br>");
}
if(flag1==0)
{
pw.println("<br><br><br>SORRY INVALID ID
TRY AGAIN ID<br><br>");
pw.println("<a href=\"order.html\">press HERE to
RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Web.xml:
<?xml version="1.0"?>
<web-app >
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>/reg</url-pattern>
</servlet-mapping>
Page 64
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

<form name="myform" method="post" action="login.jsp">


<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br /> PASSWORD :<input type="password"
name="pwd"
/></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Registration page:
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg.jsp">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
Profile.html:
Page 66
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()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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

out.println("<br><br>SORRY INVALID ID TRY AGAIN


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

Output:

Page 72
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

ADDITIONAL PROGRAMS LIST

TO CREATE TIMETABLE:

<html>

<body>

<table>

<table border=1 width="100%"align="left">

<caption align="top"><h2>TIME TABLE FOR III BTECH II


SEM(2014-15)</h2></caption>

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

<td colspan=3>AECS LAB</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

TO CREATE REGISTRATION FORM:

<html>

<head>

<title>

Registration Form

</title>

</head>

<body bgcolor="pink">

<form name="regform">

<h2>Registration Form</h2>

<h4>Student Name: <input type="text" name="sname" size="20"></h4>

<h4>Father Name : <input type="text" name="fname" size="20"></h4>

<h4>Mother Name : <input type="text" name="mname" size="20"></h4>

<h4>Date Of Birth: <input type="Date" name="bday" size="20"></h4>

<h4>Address : <Textarea cols="20" rows="5" name="taname" value=""


size="20"></textarea></h4>

Page 77
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

<h4>E-Mail : <input type="email" name="email" value="" size="20"></h4>

<h4>Phone No : <input type="text" name="phno" value="" size="20"></h4>

<h4>Select Gender:</h4>

<input type="radio" name="gender" value="Male">Male

<input type="radio" name="gender" value="FeMale">FeMale

<input type="radio" name="gender" value="Others">Others

<h4>Educational Qualification: </h4>

<h4><input type="checkbox" name="option1" value="SSC" size="20">SSC

<input type="checkbox" name="option2" value="Inter" size="20">Inter

<input type="checkbox" name="option3" value="Degree" size="20">Degree

<input type="checkbox" name="option4" value="Others" size="20">Others

<h4>Nationality:</h4>

<select name="My_menu" value="My_menu">

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

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

<input type="reset" value="Reset">

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

WEB TECHNOLOGIES VIVA QUESTIONS

HTML

1. What is HTML?

HTML (HyperText Markup Language) is a Universal language which allows an


individual using special code to create web pages to be viewed on the Internet.

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.

3. What is the simplest HTML page?

HTML Code:

<HTML><HEAD><TITLE>This is my page title! </TITLE></HEAD>

Page 80
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

<BODY> This is my message to the world! </BODY></HTML>

Browser Display: This is my message to the world!

4. How do I create frames? What is a frameset?

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.

5. How can I include comments in HTML?

An HTML comment begins with “<!—“, ends with “--> “, and does not contain “--“ or
“>” anywhere in the comment.

6. What is a Hypertext link?

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.

7. What is a DOCTYPE? Which one do I use?

According to HTML standards, each HTML document begins with a DOCTYPE


declaration that specifies which version of HTML the document uses. Many browsers use
the document’s DOCTYPE declaration to determine whether to use a stricter, more
standards-oriented layout mode, or to use a “quirks” layout mode that attempts to emulate
older, buggy browsers.

8. Can I nest tables within tables?

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.

9. How do you align a table to the right (or left)?

You use the <table align=”right”> property to float a table to the right. Put left in place of
right to float right.

10. How can I use tables to structure forms?

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.

11. How do I open a link into a new window?

Add target=”_blank” to your link syntax.

JavaScript:

1. What’s relationship between JavaScript and ECMAScript? 

ECMAScript is yet another name for JavaScript (other names include LiveScript). The
current JavaScript that you see supported in browsers is ECMAScript revision

2. What are JavaScript types? 

Number, String, Boolean, Function, Object, Null, Undefined.

3. How do you convert numbers between different bases in JavaScript? 

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

4. What does isNaN function do? 

Return true if the argument is not a number.

5. What is negative infinity? 

It’s a number in JavaScript, derived by dividing negative number by zero.

6. What boolean operators does JavaScript support? 

Page 82
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

&&, || and !

7. What does "1"+2+4 evaluate to? 

Since 1 is a string, everything is a string, so the result is 124.

8. How about 2+5+"8"? 

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so
78 is the result.

9. What looping structures are there in JavaScript? 

for, while, do-while loops, but no foreach.

10. How do you create a new object in JavaScript? 


var obj = new Object(); or var obj = {};

11. How do you assign object properties? 

obj["age"] = 17 or obj.age = 17.

12. What’s a way to append a value to an array? 

arr[arr.length] = value;

13. What is this keyword? 

It refers to the current object.

14. JavaScript gives HTML designers a programming tool

 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

15. JavaScript can react to events

 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.

16. JavaScript can read and write HTML elements

A JavaScript can read and change the content of an HTML element

17. JavaScript can be used to validate data

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

18. JavaScript can be used to detect the visitor's browser 

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

CSS Interview Questions

1. What are Cascading Style Sheets?

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?

ID selector is an individually identified (named) selector to which a specific style is


declared. Using the ID attribute, the declared style can then be associated with one and only
one HTML element per document as to differentiate it from all the other elements. They
use the # character followed by a name.

5. What is contextual selector?

A contextual selector addresses a specific occurrence of an element. It is a string of


individual selectors separated by white space, a search pattern, where only the last element
in the pattern is addressed providing it matches the specified context. Example: “ td li
{color: red} “

Page 84
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

6. What does \ABCD (and \ABCDE) mean?

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:

.\041B\041F {font-style: italic;}

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.

7. What are the advantages / disadvantages of various style methods?

External Style Sheet Advantages

 Can control styles for multiple documents at once.


 Classes can be created for use on multiple HTML element types in many documents.
 Selector and grouping methods can be used to apply styles under complex contexts.

External Style Sheet Disadvantages

 An extra download is required to import style information for each document.


 The rendering of the document may be delayed until the external style sheet is loaded.

Embedded Style Sheet Advantages

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

Inline Style Disadvantages

 Does not distance style information from content.


 Cannot control styles for multiple documents at once.
 Author cannot create or control classes of elements to control multiple element types
within the document.
 Selector grouping methods cannot be used to create complex element addressing
scenarios.
8. What is property?

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.

9. What is the CSS clear property?

The clear property specifies which sides of an element where other floating elements
are not allowed.

 This method cannot control styles for multiple documents at once.

Inline Style Advantages

 Useful for small quantities of style definitions.


 Can override other style specification methods at the local level so only exceptions
need to be listed in conjunction with other style methods.
10. What are the necessities of using HTML forms?
1. Gathering user information
2. Conducting Surveys
3. Interactive services
11. What are the sequences of steps for each HTTP request from a client to the server?
1. Making the connection
2. Making a request
3. The response
4. Closing the connection

What is XML?

 XML stands for EXtensible Markup Language

 XML is a markup language much like HTML

 XML was designed to carry data, not to display data

 XML tags are not predefined. You must define your own tags

 XML is designed to be self-descriptive

 XML is a W3C Recommendation

Page 86
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

The Difference Between XML and HTML

XML is not a replacement for HTML.

XML and HTML were designed with different goals:

 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

 HTML is about displaying information, while XML is about carrying


information.

Some advantages of XML are: 

 It is a platform independent language.


 It is as easy as HTML.
 XML is fully compatible with applications like JAVA, and it can be combined
with any application which is capable of processing XML irrespective of the
platform it is being used on.
 XML is an extremely portable language to the extent that it can be used on large
networks with multiple platforms like the internet, and it can be used on
handhelds or palmtops or PDAs.
 XML is an extendable language, meaning that you can create your own tags, or
use the tags which have already been created.
 It can be deployed on any network if it is amicable for usage with the application
in use.
 If the application can work along with XML, then XML can work on any
platform and has no boundaries.
 It is also vendor independent and system independent. While data is being
exchanged using XML, there will be no loss of data even between systems that
use totally different formats.

Servlets:

Q: Explain the life cycle methods of a Servlet.

A: The javax.servlet.Servlet interface defines the three methods known as life-cycle


method.
public void init(ServletConfig config) throws ServletException

Page 87
COMPUTER NETWORKS & WEB TECHNOLOGIES LAB MANUAL
MLRITM

public void service( ServletRequest req, ServletResponse res) throws ServletException,


IOException

public void destroy()

First the servlet is constructed, then initialized wih the init() method.


Any request from client are handled initially by the service() method before delegating
to the doXxx() methods in the case of HttpServlet.

The servlet is removed from service, destroyed with the destroy() methid, then garbaged
collected and finalized.

Q: What is the difference between the getRequestDispatcher(String path) method of


javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

A: The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface


accepts parameter the path to the resource to be included or forwarded to, which can be
relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as
relative to the current context root.

The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface


cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to
curent context root.

Q: Explain the directory structure of a web application.

A: The directory structure of a web application consists of two parts.


A private directory called WEB-INF
A public resource directory which contains public resource folder.

WEB-INF folder consists of


1. web.xml
2. classes directory
3. lib directory

Q: What are the common mechanisms used for session tracking?

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.

Q: What is preinitialization of a servlet?

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.

Q: What is the difference between Difference between doGet() and doPost()?

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.

Q: What is the difference between HttpServlet and GenericServlet?

A: A GenericServlet has a service() method aimed to handle requests. HttpServlet extends


GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus
doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).
Both these classes are abstract.

Q: What is the difference between ServletContext and ServletConfig?

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.

1. What is the difference between JSP and Servlets ?

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.

2. 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. To use custom JSP tags, you need to define three
separate components: the tag handler class that defines the tag’s behavior ,the tag
library descriptor file that maps the XML element names to the tag implementations
and the JSP file that uses the tag library
 JavaBeans are Java utility classes you defined. Beans have a standard format for Java
classes. You use tags
 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.
3. What are the different ways for session tracking?

Cookies, URL rewriting, HttpSession, Hidden form fields


4. What mechanisms are used by a Servlet Container to maintain session information?

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?

There are three scripting language elements: declarations, scriptlets, expressions.


3. How do I include static files within a JSP page?

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.

5. What is the difference in using request.getRequestDispatcher() and


context.getRequestDispatcher()?
In request.getRequestDispatcher(path) in order to create it we need to give the relative
path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create
it we need to give the absolute path of the resource.
6. What are the lifecycle of JSP?
When presented with JSP page the JSP engine does the following 7 phases.
 Page translation: -page is parsed, and a java file which is a servlet is created.
 Page compilation: page is compiled into a class file
 Page loading : This class file is loaded.
 Create an instance :- Instance of servlet is created
 jspInit() method is called
 _jspService is called to handle service calls
 _jspDestroy is called to destroy it when the servlet is not required.
7. What are context initialization parameters?
Context initialization parameters are specified by the in the web.xml file, these are
initialization parameter for the whole application.
8. What is a Expression?
Expressions are act as place holders for language expression, expression is evaluated
each time the page is accessed. This will be included in the service method of the
generated servlet.
9. What is a Declaration?
It declares one or more variables or methods for use later in the JSP source file. A
declaration must contain at least one complete declarative statement. You can declare any
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. This will be included in the declaration section of the generated servlet.
10. What is a Scriptlet?

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.

3. What are the general advantages and selling points of Servlets?

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.

4. Which package provides interfaces and classes for writing servlets? 

javax

5. What’s the Servlet Interface?

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

such as HttpServlet.Servlets > Generic Servlet > HttpServlet > MyServlet.


The Servlet interface declares, but does not implement, methods that manage the servlet
and its communications with clients. Servlet writers provide some or all of these methods
when developing a servlet.

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.

7. What information does ServletRequest allow access to?

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.

8. What type of constraints can ServletResponse interface set on the client?

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.

1. Explain servlet lifecycle?

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.

2. How does HTTP Servlet handle client requests?

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

JDBC interview questions and answers

1. What are the steps involved in establishing a JDBC connection?

This action involves two steps: loading the JDBC driver and making the connection.

2. How can you load the drivers?

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

3. What will Class.forName do while loading drivers? 


It is used to create an instance of a driver and register it with the DriverManager. When you
have loaded a driver, it is available for making a connection with a DBMS.
4. How can you make the connection?

 To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:

String url = “jdbc:odbc:Fred”;


Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);

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

executeUpdate. It takes an instance of an active connection to create a Statement object. In


the following example, we use our Connection object con to create the Statement object

Statement stmt = con.createStatement();

6. How can you retrieve data from the ResultSet?

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.

ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);


String s = rs.getString(”COF_NAME”);

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.

7. What are the different types of Statements?

Regular statement (use createStatement method), prepared statement (use prepareStatement


method) and callable statement (use prepareCall)

8. How can you use PreparedStatement? 

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.

9. PreparedStatement updateSales = con.prepareStatement("UPDATE COFFEES SET SALES


= ? WHERE COF_NAME LIKE ?");

10. What does setAutoCommit do?


When a connection is created, it is in auto-commit mode. This means that each individual
SQL statement is treated as a transaction and will be automatically committed right after it

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.

12. CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");

13. ResultSet rs = cs.executeQuery();

JSP interview questions and answers

1. What is JSP? Describe its concept. 

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.

2. What are the lifecycle phases of a JSP?

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.

B.        Page compilation: page is compiled into a class file

C.        Page loading : This class file is loaded.

D.        Create an instance :- Instance of servlet is created

E.        jspInit() method is called

F.         _jspService is called to handle service calls

G.        _jspDestroy is called to destroy it when the servlet is not required.

3.         What is a translation unit? 

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.

3. How is JSP used in the MVC model?


  JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it
plays the role of the view. The controller deals with calling the model and the business
classes which in turn get the data, this data is then presented to the JSP for rendering on to
the client.
4. What are context initialization parameters?
 Context initialization parameters are specified by the <context-param> in the web.xml file,
these are initialization parameter for the whole application and not specific to any servlet or
JSP.
5. What is a output comment?
A comment that is sent to the client in the viewable page source. The JSP engine handles an
output comment as un-interpreted HTML text, returning the comment in the HTML output
sent to the client. You can see the comment by viewing the page source from your Web
browser.
6. What is a Hidden Comment?
 A comment that documents the JSP page but is not sent to the client. The JSP engine
ignores a hidden comment, and does not process any code within hidden comment tags. A
hidden comment is not sent to the client, either in the displayed JSP page or the HTML page
source. The hidden comment is useful when you want to hide or “comment out” part of your
JSP page.
7. What is a Expression?
 Expressions are act as place holders for language expression, expression is evaluated each
time the page is accessed.
8. What is a Declaration?
It declares one or more variables or methods for use later in the JSP source file. A
declaration must contain at least one complete declarative statement. You can declare any

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.

 Classes and Interfaces of Servlet:

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

A filter is an object that performs filtering tasks on either the


Filter request to a resource (a servlet or static content), or on the
response from a resource, or both. 

A FilterChain is an object provided by the servlet container to


FilterChain the developer giving a view into the invocation chain of a
filtered request for a resource. 

A filter configuration object used by a servlet container to


FilterConfig
pass information to a filter during initialization. 

Defines an object that receives requests from the client and


RequestDispatcher sends them to any resource (such as a servlet, HTML file, or
JSP file) on the server. 

Servlet Defines methods that all servlets must implement. 

A servlet configuration object used by a servlet container to


ServletConfig
pass information to a servlet during initialization. 

Defines a set of methods that a servlet uses to communicate


ServletContext with its servlet container, for example, to get the MIME type
of a file, dispatch requests, or write to a log file. 

Implementations of this interface receive notifications of


ServletContextAttributeListene
changes to the attribute list on the servlet context of a web
r
application. 

Implementations of this interface receive notifications about


ServletContextListener changes to the servlet context of the web application they are
part of. 

Defines an object to provide client request information to a


ServletRequest
servlet. 

Page 101

You might also like