WEB TECHNOLOGIES Lab Manual
WEB TECHNOLOGIES Lab Manual
WEB TECHNOLOGIES Lab Manual
TECHNOLOGI
ES
LAB
MANUAL
FOR
IT
INDEX
S. No Contents Page. No
1 Lab Objective 3
3 Guidelines to Students 6
Page2
LAB OBJECTIVE
Advance Programming
Page3
INTRODUCTION ABOUT LAB
RAM : 256 MB
Hard Disk : 40 GB
Software
All systems are configured in DUAL BOOT mode i.e., Students can boot from Windows
XP or Linux as per their lab requirement.
This is very useful for students because they are familiar with different Operating
Systems so that they can execute their programs in different programming
environments.
Oracle 9i client version is installed in all systems. On the server, account for each
student has been created.
This is very useful because students can save their work ( scenarios’, pl/sql
programs, data related projects ,etc) in their own accounts. Each student work is safe and
secure from other students.
Latest Technologies like DOTNET and J2EE are installed in some systems.
nd
Before submitting their final project, they can start doing mini project from 2
year onwards.
Students can execute their assembly language programs using MASM. MASM is
very useful students because when they execute their programs they can see
contents of Processor Registers and how each instruction is being executed in the
CPU.
Page4
Rational Rose Software is installed in some systems. Using this software, students
can depict UML diagrams of their projects.
Systems are assigned numbers and same system is allotted for students when they do
the lab.
Page5
Guidelines to Students
Equipment in the lab for the use of student community. Students need to maintain a
proper decorum in the computer lab. Students must use the equipment with care. Any
damage is caused is punishable.
Students are required to carry their observation / programs book with completed exercises
while entering the lab.
Students are supposed to occupy the machines allotted to them and are not supposed to
talk or make noise in the lab. The allocation is put up on the lab notice board.
Lab can be used in free time / lunch hours by the students who need to use the systems
should take prior permission from the lab in-charge.
Page6
Web Technologies Syllabus Programs (JNTU)
Programs
S.No
Develop static pages (using only HTML) of an online Book store. The
pages should resemble: www .amazon.com
1, 2 The website should consist the following pages.
Home page, Registration and user Login, User profile page, Books
catalog, Shopping cart, Payment By credit card, order confirmation.
Validate the registration, user login, user profile and payment by credit
3, 4 card pages using JavaScript.
Write an XML file which will display the Book information which
includes the following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML
5 file.
VISUAL BEANS:
Create a simple visual bean with a area filled with a color. The shape of
6 the area depends on the property shape. If it is set to true then the
shape of the area is Square and it is Circle, if it is false. The color of
the area should be changed dynamically for every mouse click.
Page7
User Authentication :
Assume four users user1, user2, user3 and user4 having the passwords
pwd1, pwd2, pwd3 And, pwd4 respectively. Write a servelet for doing
8 the following.
1. Create a Cookie and add these four user id’s and passwords to this
Cookie.
2. Read the user id and passwords entered in the Login form (week1)
and authenticate with the values (user id and passwords ) available in the
cookies. If he is a valid user(i.e., user-name and password match) you
should welcome him by name(user-name) else you should display “ You
are not an authenticated user “.
Page8
WEEK- 1, 2:
AIM:
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.
Home page
Registration and user Login
User profile page
Books catalog
Shopping cart
Payment by credit card Order Conformation
PROCEDURE:
Home page
Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"> <center> <strong><h1>Welcome
to AMAZON</h1></strong> <form method="post"
action="login.html" target=_blank >
<h4>for books</h4><input type="submit" value="click here">
</form>
</center>
</body>
</html>
Page9
Registration and user Login
Login.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan"> <center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="userpro.html" >
<input type="submit" value="register" >
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>
Page10
User profile page
Userpro.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table
align="left"> <tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>male
<option >
<input type="radio" name="sex"
id="male"></td> <td><h4>female
<input type="radio" name="sex" id="female"
></td> </option>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5
cols=19> </textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset"
value="reset"></td> </tr>
Page11
</form>
</body>
</html>
Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center> <form
method="post" action="shopping.html"> <left>
<table>
<tr>
<td><b><h3>frontend
books</td> <td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
Page12
<td></td>
<td><h4>MySql
</td> </tr>
</table>
</h4>
<center>
<b>for buy one of these
books <br>
</b><input type="submit" value="click
here"> </center>
</form>
</body>
</html>
Shopping cart
Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select >
<optgroup label="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads <option
value="Java">Java <option
value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL
Server <option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text"
id="q"> </td></tr>
Page13
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping
"100"</pre> </center>
<body>
</html>
Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="cyan">
<center><h1>Payment By Credit Card</h1></center>
<form method=post action="ordrconform.html">
<br><br><br><br><br>
<table align="center">
<tr>
<td>
<h4>Total Amount</h4></td>
<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>
Page14
Order Conformation
Ordrconform:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
Page15
OUTPUT:
Main.html:
Login.html:
Page16
Catalog.html:
Userpro.htm
Page17
Shooping.html:
Payment.html:
Page18
Ordrconform.html:
Page19
WEEK- 3, 4 :
AIM
Validate the Registration, user login, user profile and payment by credit
card pages using JavaScript.
PROCEDURE:
Home page:
Main.html:
<html>
<frameset rows="25%,*">
<frame src="top.html" name="top" scrolling ="no" frameborder ="0">
<frameset cols="25%,75%">
<frame src="left.html" name="left" scrolling ="no" frameborder ="0">
<frame src="right.html" name="right" scrolling ="auto" frameborder
="0"> </frameset>
</frameset>
</html>
Top.html:
<html>
<body bgcolor="pink">
<br><br>
<marquee><h1 align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>
Page20
Right.html:
<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press login if you
are having id otherwise press registration.
</p></b></h2>
</body> </html>
Left.html:
<html>
<body
bgcolor="pink"> <h3>
<ul>
<li><a href="login.html" target="right"><font
color="black"> LOGIN</font></a></li><br><br>
<li><a href="profile.html" target="right"><font color="black">
USER PROFILE</font></a></li><br><br>
<li><a href="catalog.html" target="right"><font
color="black"> BOOKS CATALOG</font></a></li><br><br>
<li><a href="scart.html" target="right"><font
color="black"> SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font color="black">
PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Page21
Registration and user Login
Login.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.pwd.value=="")
{
alert("LoginId and Password must be
filled") flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.open("catalog.html","right");
}
else
{
alert("INVALID
INPUT");
//document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password" name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</div>
</form>
</body>
</html>
Page22
User profile page
Profile.html:
<html>
<body bgcolor="pink"><br><br>
<script type="text/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=="")
{
alert("Enter all the details");
flag=0;
}
var str=document.myform.phno.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
if(!(str.length==10))
flag=0;
}
var str1=document.myform.id.value;
var x1=new RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid UserID");
}
var str1=document.myform.pwd.value;
var x1=new RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid password");
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="login.html";
}
Page23
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="type" name="addr"><br>
CONTACT NUMBER:<input type="text" name="phno"><br>
LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form></body></html>
Books catalog:
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.title.value=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c"||str=="C")
{
document.myform.t1.value="C";
document.myform.t2.value=444;
}
else if(str=="jsp"||str=="JSP")
Page24
{
document.myform.t1.value="JSP";
document.myform.t2.value=555;
}
else
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" action="payment.html" target="right">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br>
</pre><br><br>
Book Title: <input type="text" name="t1" disabled>
Book Cost: <input type="text" name="t2" disabled>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
<input type="submit" value="Purchase">
</form>
</body>
</html>
Page25
Shopping cart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.title.value==""||
document.myform.no.value==""||
document.myform.cost.value=="")
{
flag=0;
}
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" action="scart.html" target="right">
<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>
COST OF BOOK :<input type="text"name="cost"><br>
</pre><br><br>
Page26
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
if(!(str.match(x1)))
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="order.html";
}
else
{
Page27
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input type="text" name="amount"><br>
CREDITCARDNUMBER :<input type="PASSWORD" name="num"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
</html>
Order Conformation
Order.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
Page28
OUTPUT:
Main.html
Login.html:
Page29
Catalog.html:
Scart.html:
Page30
Payment.html:
Order.html
Page31
WEEK-5.
AIM: Write an XML file which will display the Book information which includes the
following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML file.
The contents should be displayed in a table. The header of the table should be in color GREY.
And the Author names column should be displayed in one color and should be capitalized and in
bold. Use your own colors for remaining columns. Use XML schemas XSL and CSS for the
above purpose.
1. Books.DTD:
2. Th.CSS
.thb
{
background-color:gray;
}
.bg
{
background-color:red;
}
Page32
3. Books.XML:
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM
"books.dtd"> <book>
<details>
<title> C</title>
<author> BalaGuru Swami</author>
<ISBN_Number>2536</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>255/-</price>
</details>
<details>
<title> C++</title>
<author> BalaGuru Swami</author>
<ISBN_Number>5236</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>315/-</price>
</details>
<details>
<title> E-Commerce</title>
<author> Kalakata</author>
<ISBN_Number>8562</ISBN_Number>
<publisher>pearson</publisher>
<edition>5</edition>
<price>300/-</price>
</details>
<details>
<title> CO</title>
<author> Marris </author>
<ISBN_Number>4578</ISBN_Number>
<publisher>Dream Tech</publisher>
<edition>5</edition>
<price>270/-</price>
</details>
<details>
<title> Web Technologies</title>
<author> Kumar </author>
<ISBN_Number>5423</ISBN_Number>
<publisher>Willay</publisher>
<edition>6</edition>
Page33
<price>500/-</price>
</details>
<details>
<title> Web Programming</title>
<author> Kumar </author>
<ISBN_Number>1258</ISBN_Number>
<publisher>Willay</publisher>
<edition>6</edition>
<price>500/-</price>
</details>
</book>
4. Books.HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="th.css">
</head>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera,
Safari xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("details")
document.write("<tr><th class='thb'>");
document.write("TITLE</th><th class='thb'>AUTHOR</th><th
class='thb'>ISBN_Number</th><th class='thb'>PUBLISHER</th><th
class='thb'>EDITION</th><th class='thb'>PRICE</th></tr>");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("</td><th class='bg'>");
Page34
document.write(x[i].getElementsByTagName("author")[0].childNodes[0].nodeValue.toU
pperCase());
document.write("</th><td>");
document.write(x[i].getElementsByTagName("ISBN_Number")[0].childNodes[0].nodeV
alue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("publisher")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("edition")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
Page35
OUTPUT:
Page36
Week-6:
VISUAL BEANS:
Create a simple visual bean with a area filled with a color. The shape of the area depends on the
property shape. If it is set to true then the shape of the area is Square and it is Circle, if it is false.
The color of the area should be changed dynamically for every mouse click.
Process:
Create a New Bean
Here are the steps that you must follow to create a new Bean:
1. Create a directory for the new Bean.
2. Create the Java source file(s).
3. Compile the source file(s).
4. Create a manifest file.
5. Generate a JAR file.
6. Start the BDK.
7. Test.
The following sections discuss each of these steps in detail.
Page37
SOURCE CODE:- Colors.java:
import java.awt.*;
import java.awt.event.*;
public class Colors extends Canvas
{
transient private Color color;
private boolean rectangular;
public Colors()
{
addMouseListener(new MouseAdapter()
{ public void mousePressed(MouseEvent
me) { change();
}
});
rectangular = false;
setSize(200, 100);
change();
}
public boolean getRectangular()
{
return rectangular;
}
public void setRectangular(boolean flag)
{
this.rectangular =
flag; repaint();
}
public void change()
{
color = randomColor();
repaint();
}
private Color randomColor()
{
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
return new Color(r, g, b);
}
public void paint(Graphics g)
{
Dimension d = getSize();
int h = d.height;
Page38
int w = d.width;
g.setColor(color);
if(rectangular)
{
g.fillRect(0, 0, w-1, h-1);
}
else
{
g.fillOval(0, 0, w-1, h-1);
}
}
}
Manifest-Version: 1.0
Name: Colors.class
Java-Bean: True
This file indicates that there is one .class file in the JAR file and that it is a Java Bean.
Notice that the Colors.class file in the current directory.
Page39
Create an Instance of the Colors Bean
After you complete the preceding steps, create an instance of the Colors Bean in the BeanBox
window. Test your new component by pressing the mouse anywhere within its borders. Its color
immediately changes. Use the Properties window to change the rectangular property from false
to true. Its shape immediately changes.
Page40
Screen shot for triangle:
Page41
Week-7:
1) Install TOMCAT web server. While installation assign port number 8080. Make sure that
these ports are available i.e., no other process is using this port.
2) Access the above developed static web pages for books web site, using these servers
by Putting the web pages developed in week-1 and week-2 in the document root.
Access the pages by using the urls : http://localhost:8080/rama/books.html
Step 1:
Installation of JDK:
Before beginning the process of installing Tomcat on your system, ensure first the availability of
JDK on your system program directory. Install it on your system if not already installed (because
any version of tomcat requires the Java 1.6 or higher versions) and then set the class path
(environment variable) of JDK. To set the JAVA_HOME Variable: you need to specify the
location of the java run time environment to support the Tomcat else Tomcat server can not run.
Note: it should not contain the path up to bin folder. Here, we have taken the URL
path according to our installation convention.
For Windows OS, go through the following steps:
My Computer->properties->advance->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:
Page42
First, right click on the
My Computer->properties->advance->Environment
Variables->path.
Step 3:
The process of installing Tomcat 6.0 begins here from now. It takes various steps for installing
and configuring the Tomcat 6.0.
For Windows OS, Tomcat comes in two forms: .zip file and .exe file (the Windows installer file).
Here we are exploring the installation process by using the .exe file. First unpack the zipped file
and simply execute the '.exe' file.
A Welcome screen shot appears that shows the beginning of installation process. Just click on
the 'Next' button to proceed the installation process.
Steps 4:
Page43
Click on the 'I Agree' button.
Step 5:
Page44
Choose the default components and click on the 'Next' button.
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:
Page45
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.
Step 8:
To get the information about installer click on the "Show details" button
Page46
Step 9:
Step 10:
A window of Apache Service Manager appears with displaying the running process.
Page47
Step 11:
After completing the installation process, the Apache Tomcat Manager appears on the
toolbar panel like shown in the below picture.
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.
2. Now Open web browser and type URL http://localhost:8080 in the address bar to test
the server
3. To Stop the Tomcat Server: Stop the server by pressing the "Ctrl + c" keys.
Page48
PROCEDURE:
Screen shot:
Page49
Week-8:
User Authentication :
Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3
And, pwd4 respectively. Write a servelet for doing the following.
1. Create a Cookie and add these four user id’s and passwords to this Cookie.
2. Read the user id and passwords entered in the Login form (week1) and authenticate
with the values (user id and passwords ) available in the cookies.
If he is a valid user(i.e., user-name and password match) you should welcome him
by name(user-name) else you should display “ You are not an authenticated user “.
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.
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 subdirectories.
6. After this start tomcat by giving the following command at the instll_dir>tomcat>bin
7. 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.
Login.html:
<html>
<body bgcolor="pink">
<form action="show" method="get">
<center>User Name: <input type="test" name="name"><br>
Password:<input type="password" name="pass"><br>
<input type="submit" name="b1">
<input type="Button" name="b2" value="Reset">
</center>
</form>
</body>
</html>
Page50
Login.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example using servlet initialization. Here, the message
* to print and the number of times the message should be
* repeated is taken from the init parameters.
*/
public class login extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html"); String
na=request.getParameter("name"); String
pa=request.getParameter("pass"); PrintWriter
out = response.getWriter(); Cookie
nam1=new Cookie("user1","pace"); Cookie
nam2=new Cookie("user2","phani"); Cookie
nam3=new Cookie("user3","cse"); Cookie
nam4=new Cookie("user4","ece"); Cookie
pas1=new Cookie("pwd1","college");
Cookie pas2=new Cookie("pwd2","kumar");
Cookie pas3=new Cookie("pwd3","it");
Cookie pas4=new Cookie("pwd4","eee"); int
flag=0;
String nam[]={nam1.getValue(),nam2.getValue(),nam3.getValue(),nam4.getValue()};
String pas[]={pas1.getValue(),pas2.getValue(),pas3.getValue(),pas4.getValue()};
Page51
for(int i=0;i<4;i++)
{
if(nam[i].equals(na)&&pas[i].equals(pa))
{
flag=1;
}
}
if(flag==1)
{
out.println("<title>The ShowMessage Servlet</title>");
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" +"<H1 ALIGN=CENTER>
WELCOME <br/>TO</br> " +na.toUpperCase() + "</H1>");
out.println("</BODY></HTML>");
}
else
{
out.println("<title>The ShowMessage Servlet</title>");
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=CENTER>
User is invalid </H1>");
out.println("</BODY></HTML>");
}
}
}
Page52
Web.xml:
<web-app>
<servlet>
<servlet-name>log </servlet-name>
<servlet-class>login </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>log </servlet-name>
<url-pattern> /show </url-pattern>
</servlet-mapping>
</web-app>
Create a directory:
Create a directory “cookies”, in that directory copy login.html file and create a directory a
”WEB-INF”. In that WEB-INF directory again create directory “classes” and copy web.xml file.
Compile the servlet:
Compile the servlet file then copy the class file of that servlet into the directory
C:\Program Files\Apache Software Foundation\Tomcat 6.0\cookies\WEB-INF\classes.
Page53
OUTPUT:
Login.html:
Login.java:
Page54
Week-9:
Install a database(Mysql or Oracle).
Create a table which should contain at least the following fields: name, password, email-id,
phone number(these should hold the data from the registration form).
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
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login">
<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"/>
<input type="reset"
value="clear" /> </div>
</form>
</body>
</html>
Page55
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()" />
<input type="reset"
value="clear" /> </div>
</form>
</body>
</html>
Userinfo.html
<html>
<head>
<title>User Info Entry Form</title>
</head>
<body bgcolor="white">
<form action="userinfo1.jsp"
method="post"> <table>
<tr>
<td>Name:</td>
<td><input type="text" name="userName" >
</td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="text" name="sex" >
</td>
<td>(Male or female)</td>
</tr>
<tr>
<td colspan=2><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Page56
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>
<td>:<input type="password" name="pwd"
/></td> </tr>
</table> <br
/><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset"
value="clear" /> </div>
</form>
</body>
</html>
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>");
Page57
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String s1="",s2="";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system",
"tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
s1=rs.getString(4);
s2=rs.getString(5);
}
if(id.equals(s1)&&pwd.equals(s2))
{
flag=1;
}
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>WELCOME TO "+id.toUpperCase()+"<br><br>");
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());
}
}
}
Page58
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");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1522 :XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(4))&&pwd1.equals(rs.getString(5)))
{
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+"','"+phno+"','"+id1+"','"+pwd1+"')");
Page59
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());
}
}
}
Catalog.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
{
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("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","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>");
Page60
pw.println("<a href=\"catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
profile.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
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("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","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>");
}
Page61
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
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("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(4))&&pwd.equals(rs.getString(5)))
{
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
{
Page62
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 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());
}
}
}
Page63
OUTPUT:
Main.html:
Registration:
Page64
Login Page:
Page65
Profile page:
Page66
Catalog page:
Page67
Order page:
Page68
Week-10:
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
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post"
action="login.jsp"> <div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset"
value="clear" /> </div>
</form>
</body>
</html>
Page69
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()" />
<input type="reset"
value="clear" /> </div>
</form>
</body>
</html>
Page70
Reg.jsp:
Page71
Login.jsp:
<%@page import="java.sql.*"%> <
%@page import="java.io.*"%>
<html>
<body>
<% String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","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("WELCOME <br>To<br>”+id);
}
con.close();
%>
</body>
</html>
Page72
OUTPUT:
Main.html:
Registration page:
Page73
Login page:
Page74