0% found this document useful (0 votes)
182 views85 pages

WT Lab Manual Cse Jntuh

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 85

WEB Technologies lab manual

IV BTECH I SEM- CSE

WEB TECHNOLOGIES Page 1


SNO PROGRAM

1 Creation of static web pages of online book store such as HOME, LOGIN, and
CATALOGUE pages.

2 Creation of static web pages for REGISTRATION and CART pages.

3 Validation of REGISTRATION and LOGIN pages

4 Design of web pages using CSS propertie (font, background, background-repeat,


links etc),using layers and using customized cursor

5 Validation of XML file using DTD and displaying its data in a table using XSL and
CSS

6 Creation of simple visual bean with area filled with a color. The shape of area
depends on property shape, and configuration of the bean.

7 Installation of TOMCAT web server APACHE tomcat on port no 4040 and APACHE
on port no 8080

8 Hello message servlet program

9 User authentication using cookies and init parameters configured in web.xml

10 JDBC program to retrieve data from student table

11 Insertion of details in registration page into database using servlet

12 Jsp program to demonstrate usage <jsp:useBean> action element

13 Insertion of registration details and user authentication using JSP

14 Extraction of each catalog book details from database using JDBC

15 Session management program using servlet

16 JSP Source Code for Basic Arithmetic Example

17 Write a JavaScript program for selection sort

WEB TECHNOLOGIES Page 2


Week1&2:

Designing of following static web pages required for an online book store web site.
1) HOME PAGE
2) LOGIN PAGE:
3) CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the
web site in a table.
The details contain the following:
a. Snap shot of Cover Page.
b. Author Name.
c. Publisher.
d. Price.
e. Add to cart button.
4) CART PAGE:
a. The cart page contains the details about the books which are added to the
cart.
b. The cart page should look like this:
5) REGISTRATION PAGE:
“registration form “with the following fields
1) Name (Text field)
2) Password (password field)
3) E-mail id (text field)
4) Phone number (text field)
5) Sex (radio button)
6) Date of birth (3 select boxes)
7) Languages known (check boxes – English, Telugu, Hindi, Tamil)
8) Address (text area)

 Create a file in notepad and save it as “book.html”

<html>
<head><title>Book</title></head>
<frameset rows="25%,75%">
<frame src="top.html" name="top" framespacing="0" scrolling="no" frameborder="0"
noresize>
<frameset cols="15%,85%">
<frame src="left.html" name="left" framespacing="0" scrolling="auto"
frameborder="0" noresize>
<frame src="right.html" name="right" framespacing="0" scrolling="auto"
frameborder="0" noresize>
</frameset>
</frameset>
</html>

 Create a file in notepad and save with “top.html”

<html>
<head>
<title>top</title>
<style>
a:link{text-decoration:none}
a:visited {text-decoration:none;color:red}
a:hover {text-decoration:underline;color:green}
a:active {text-decoration:none;color:blue}
</style>
</head>
<body bgcolor="#fedcba" >
<p align="center">
<table height="100%" width="100%" border="0" align="center" height="100%">
<colgroup span="5" width="20%"></colgroup>
<tr align="center"><td><img src="logo.gif" width="85%" name="logo" alt="site
logo"></td><td colspan="4"><h1>AMAZON BOOKS WORLD</h1></td></tr>
<tr align="center"><td><a name="home" href="home.html"
target="right">HOME</a></td>
<td><a name="login" href="login.html" target="right">LOGIN</a></td>
<td><a name="registration" href="registration.html"
target="right">REGISTRATION</a></td>
<td><a name="catalogue" href="catalogue.html"
target="right">CATALOGUE</a></td>
<td><a name="cart" href="cart.html" target="right">CART</a></td>
</tr>
</table>
</p>
</body>
</html>

 Create a file in notepad and save it as “left.html”


<html>
<head><title>left</title>
<style>
a:link{text-decoration:none}
a:visited {text-decoration:none;color:red}
a:hover {text-decoration:underline;color:green}
a:active {text-decoration:none;color:blue}
</style>
<title>Left</title>
</head>
<body bgcolor="#fabecd">
<p align="center"><a href="ece.html" target="right">ece</a></p >
<p align="center"><a href="eee.html" target="right">eee</a></p >
<p align="center"><a href="mech.html" target="right">mech</a></p >
<p align="center"><a href="csit.html" target="right">cse</a>
</body>
</html>

 Create a file in notepad and save it as “right.html”

<html>
<head>
<title>right frame
</title>
</head>
<body bgcolor="#abcdef">
<font color='#123123' size='+3'>welcome to amazon books world</font>
<br>
This site provides the books information related to various categories.
</body>
</html>

 Create a file in notepad and save it as “home.html”

<html>
<head>
<title>home page
</title>
</head>
<body bgcolor="#abcdef">
<font color='#123123' size='+3'>welcome to amazon books world</font>
<br>
This site provides the books information related to various categories.
</body>
</html>

 Create a file in notepad and save it as “login.html”

<html>
<head>
<title>login form</title>
</head>
<body bgcolor="#abcdef">
<h3 align="center">login into the site</h3>
<form method="post">
<table align="center">
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" login "></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>

 Create a file in notepad and save it as “registration.html”

<html>
<head>
<title>Registration form</title>
</head>
<body bgcolor="orange">
<h3 align="center" color="pink">Registration form</h3>
<center>
<form name="regform" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="emai" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>&nbsp;
month&nbsp;&nbsp; <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>&nbsp;&nbsp;
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU&nbsp;&nbsp; <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI&nbsp; &nbsp;
&nbsp;&nbsp; <input type="checkbox" name="hindi" value="hindi"> </td>
</tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td>
</tr>
</table>
<br><br>
<input type="submit" align="center" value="send">&nbsp;<input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>

 Create a file in notepad and save it as “catalogue.html”

<html>
<head>
<title>catalogue page</title>
</head>
<body bgcolor="#abcdef">

<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: XML Bible<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : HTML in 24 hours<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : AI<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Java 2<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</table>
</body>
</html>

 Create a file in notepad and save it as “cart.html”

<html>
<head>
<title>cart page</title>
</head>
<body bgcolor="#abcdef">
<table align="center" width="75%">
<tr align="center"><th>Book Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
<tr align="center"><td>Java2</td>
<td>$35.5</td>
<td>2</td>
<td>$70</td>
</tr>
<tr align="center"><td>XML Bible</td>
<td>$40.5</td>
<td>1</td>
<td>$40.5</td>
</tr>
<tr align="right"><th colspan="4">Total amount -$110</th>
</table>
</body>
</html>

 Create a file in notepad and save it as “csit.html”

<html>
<head>
<title>csit books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Computer Science & IT Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Mobile Computing<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Computer Networks<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Computer Communications<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Web Design<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>

 Create a in notepad and save it as “eee.html”

<html>
<head>
<title>eee books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Electrical and Electronics Eng. Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Machines<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Power Electronics<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Transmision Systems<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Network Theory<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>

 Create a file in notepad and save it as “ece.html”

<html>
<head>
<title>ece books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Electronics & Communtion Eng. Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Micro Processor<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Priciples of Communtion<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Digital Logic Design<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Signal Processing<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>
Output:
WEEK 3:

VALIDATION:

a) Using JavaScript to validate the following fields of the registration page.

1. Name (Name should contains alphabets and the length should not be less
than 6 characters).
2. Password (Password should not be less than 6 characters length).
3. E-mail id (should not contain any invalid and must follow the standard pattern
[email protected])
4. Phone number (Phone number should contain 10 digits only).

b) Also validate the login page with these parameters.

Create a file in notepad and save with “registration.html” which contains javascript code
to validate the name,password,e-mail and phone number entered in registration page.

<html>
<head>
<title>login form</title>
<script language="javascript">
function validate()
{
name=document.forms[0].elements[0].value;
pwd=document.forms[0].elements[1].value;
name_re=new RegExp("^[A-Za-z][a-zA-Z .]+$","g");
pwd_re=new RegExp("^[0-9a-zA-Z]+$","g");
if(name.match(name_re))
{
if(pwd.match(pwd_re))
{
alert("login successful");
}
else
{
alert(" invalid password");
document.forms[0].elements[1].select();
}
}
els
e
{
alert("invalid user name");
document.forms[0].elements[0].select();
}

}
</script>
</head>
<body bgcolor="#abcdef">
<h3 align="center">login into the site</h3>
<form method="post">
<table align="center">
<tr><td>name</td><td><input type="text"
name="uname"></td></tr>
<tr><td>password</td><td><input type="password"
name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" login "
onClick="validate()"></td><td><input type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>

 Crate a file in notepad and save with “login.html” , contains javascript code for
login form validation

<html>
<head>
<title>Registration form</title>
<script language="javascript">
function validate()
{
var flag=true;
var name=document.forms[0].elements[0].value;
var pwd=document.forms[0].elements[1].value;
var phno=document.forms[0].elements[2].value;
var email=document.forms[0].elements[3].value;

name_re=new RegExp("^[A-Za-z][a-zA-Z .]+$","g");


pwd_re=new RegExp("^[0-9a-zA-Z]+$","g");
email_re=new RegExp("^[a-zA-Z][\\w_.]+[@][\\w]+[.][a-zA-Z]+$","g");
phno_re=new RegExp("^[\\d]+","g");

if(!name.match(name_re))
{
alert(" name contains only alphabets only");
flag=false;
document.forms[0].elements[0].select();
}
if(name.length<6)
{
flag=false;
alert("name should contain atleast 6 characters");
document.forms[0].elements[0].select();
}

if(!pwd.match(pwd_re))
{
flag=false;
alert(" password should contain alphanumerics only");
document.forms[0].elements[1].select();
}
if(pwd.length<6)
{
flag=false;
alert("password should contain atleast 6 characters");
document.forms[0].elements[1].select();
}

if(!phno.match(phno_re))
{
flag=false;
alert(" invalid phone number");
document.forms[0].elements[2].select();
}
if(phno.length<10)
{
flag=false;
alert("phone number should contain 10 digits ");
document.forms[0].elements[2].select();
}
if(!email.match(email_re))
{
flag=false;
alert(" invalid email");
document.forms[0].elements[3].select();

}
if(flag==true)
alert("registration is successful");
else
alert("registration is faild");
}
</script>
</head>
<body bgcolor="orange">
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./RegServlet" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="email" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>&nbsp;
month&nbsp;&nbsp; <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>&nbsp;&nbsp;
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU&nbsp;&nbsp; <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI&nbsp; &nbsp;
&nbsp;&nbsp; <input type="checkbox" name="hindi" value="hindi"></td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="button" align="center" value="send" onClick="validate()">&nbsp;<input
type="reset" align="center" value="cancel">
</form>
</center>
</body>
</html>
Output:
Week-4:

Designing a web page using CSS (Cascading Style Sheets) which includes the
following:

a) Use different font, styles


b) Setting a background image for both the page and single elements on the page.
c) Controlling the repetition of the image with the background-repeat property.
d) Defining the styles for links as
A:link
A:visited
A:active
A:hover
e) Working with layers
f) Adding a customized cursor

PROGRAM NO:4(a)
 Create file in notepad and save with “fonts.html”

<html>
<head>
<link rel="stylesheet" type="text/css" href="test1.css">
</head>
<body>
<h1>This header is red</h1>
<h2>This header is blue</h2>
<p> This text is normal</p>
</body>
</html>

 Create file in notepad and save with “test1.css”

h1{color:red;font-size:22px;font-family:arial;text-decoration:underline}
h2{color:blue;font-size:16px}
p{font-family:arial;font-size:30px}

PROGRAM NO:4(b)

 Create file in notepad and save with “backgrounds..html”

<html>
<head>
<style type="text/css">
body{ background-image:url("flower.jpg");
background-repeat:no-repeat; }
</style>
</head>
<body>
<center>
<h1>Life is beautiful!!!</h1>
<h2>Strength is live</h2>
<h2>weakness is death</h2>
</center>
</body>
</html>
PROGRAM NO:4(c)

 Create file in notepad and save with “bg_property.html”

<html>
<head>
<style type="text/css">
body{ background-image:url("flower1.jpg");
background-repeat:repeat;
}
h1{ color:green;
font-size:35px;
}
</style>
</head>
<body>
<center>
<h1>Life is beautiful!!!</h1>
<h2>Strength is live</h2>
<h2>weakness is death</h2>
</center>
</body>
</html>

PROGRAM NO:4(d)

 Create file in notepad and save with “links.html”

<html>
<head>
<link rel="stylesheet" type="text/css" href="test4.css" media="screen">
</head>
<body>
<h1>This style sheet is for links</h1>
<p>You can experiment with the following link</p>
<p><a href="http://www.google.co.in">This is a link</a></p>
</body>
</html>

 Create file in notepad and save with “test4.css”

body{ background-color:"#abccba"}
h1{ color:black;font-size:22pt}
p{font-size:12pt;margin-left:15px}
a:link{color:blue}
a:visited{color:purple}
a:hover{color:red;text-decoration:underline}
a:active{color;green}

PROGRAM NO:4(e)

 Create file in notepad and save with “layers.html”

<html>
<head>
<title>Layers Demo</title>
</head>
<body>
<div style="position:relative;font-size:50px;left:50;top:10;background-
color:red;z-index:1 width:20; height:60" >layer1</div>
<div style="position:relative;font-size:50px;left:150;top:3;background-
color:green;z-index:2">layer2</div>
<div style="position:relative;font-size:25px;left:200;top:-5;background-
color:blue;z-index:3">layer1</div>
</body>
</html>

PROGRAM NO:4(e)
 Create file in notepad and save with “cursors.html”

<html>
<head>
<title> customized cursor</title>
<style>
.alink{cursor:auto}
.xlink{cursor:crosshair}
.dlink{cursor:default}
.rslink{cursor:e-resize}
.hlink{cursor:help}
.mlink{cursor:move}
.nrlink{cursor:n-resize}
.nelink{cursor:ne-resize}
.nwlink{cursor:nw-resize}
.plink{cursor:pointer}
.proglink{cursor:progress}
.slink{cursor:s-resize}
.selink{cursor:se-resize}
.swlink{cursor:sw-resize}
.tlink{cursor:text}
.wlink{cursor:w-resize}
.waitlink{cursor:wait}
</style>
<body>
<p>Mouse over the words to change the cursor.</p>
<span class="alink">auto</span><br />
<span class="xlink">crosshair</span><br />
<span class="dlink">default</span><br />
<span class="rslink">e-resize</span><br />
<span class="hlink">help</span><br />
<span class="mlink">move</span><br />
<span class="nrlink">n-resize</span><br />
<span class="nelink">ne-resize</span><br />
<span class="nwlink">nw-resize</span><br />
<span class="plink">pointer</span><br />
<span class="proglink">progress</span><br />
<span class="slink">s-resize</span><br />
<span class="selink">se-resize</span><br />
<span class="swlink">sw-resize</span><br />
<span class="tlink">text</span><br />
<span class="wlink">w-resize</span><br />
<span class="waitlink">wait</span><br />
</body>
</html>
Output:
Week-5:

A. An XML file which will display the Book information which includes the following:

a. Title of the book


b. Author Name
c. ISBN number
d. Publisher name
e. Edition
f. Price
A Document Type Definition (DTD) file to validate the above XML file.

B. Displaying the XML file as follows.

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.
Usage of XML schemas XSL and CSS for the above purpose.

5(A) Create file in notepad which contains schema definition for the XML file and save
with “catalogue.dtd”

<?xml version="1.0" encoding="UTF-8" ?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Catalog">
<xs:complexType>
<xs:sequence>
<xs:element ref="Book" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Book">
<xs:complexType>
<xs:sequnece>
<xs:element ref="Title" minOccurs="1" maxOccurs="1" />
<xs:element ref="Author" minOccurs="1" maxOccurs="1" />
<xs:element ref="Publication" minOccurs="1" maxOccurs="1" />
<xs:element ref="Edition" minOccurs="1" maxOccurs="1" />
<xs:element ref="ISBN" minOccurs="1" maxOccurs="1" />
<xs:element ref="Price" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Title" type="xs:string" />
<xs:element name="Author" type="xs:string" />
<xs:element name="Publication" type="xs:string" />
<xs:element name="Edition" type="xs:string" />
<xs:element name="ISBN" type="xs:string" />
<xs:element name="Price" type="xs:string" />
</xs:schema>

 Create file in notepad which contains the styles for the tags in XML file and save
with “library.css”

Catalog
{
font-family:arial;
color:red;
font-size:16pt
}

Book
{
display:block;
font-family:"times new Roman";
font-color:blue;
table-layout:auto;
font-size:14pt
}
Title
{
font-family:arial;
color:blue;
font-size:14pt
}

Autho

r font-family:arial;
{ color:red;

}
Publication,Edition,ISBN,Price
{
disp
lay:
bloc
k;
font
-
fam
ily:
aria
l;
colo
r:m
aro
on;
font
-
size
:10
pt;
mar
gin-
left:
20p
t;
}

 Create an XML file which contain information about books and save with

c
a
t
a
l
o
g
.
x
m
l

<?xml version="1.0" encoding="UTF-8" ?>


<?xml-stylesheet type="text/css" href="library.css" ?>
<Catalog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:noNamespaceSchemaLocation="catalog.xsd">
<Book>
<Title>XML Bible</Title>
<Author>Winston</Author>
<Publication>Wiely</Publication>
<Edition>Fifth Edition</Edition>
<ISBN>0-7645-4760-7</ISBN>
<Price>$40.5</Price>
</Book>
<Book>
<Title>Artificial Intelegence</Title>
<Author>S.Russel</Author>
<Publication>Princeton Hall</Publication>
<Edition>Sixth Edition</Edition>
<ISBN>0-13-1038-5-2</ISBN>
<Price>$63</Price>
</Book>
<Book>
<Title>Java2</Title>
<Author>Watson</Author>
<Publication>BPB Publications</Publication>
<Edition>Third Edition</Edition>
<ISBN>0-41-1058-7-2</ISBN>
<Price>$60</Price>
</Book>
<Book>
<Title>HTML in 24 hours</Title>
<Author>Sam Peter</Author>
<Publication>SAM Publications</Publication>
<Edition>Fifth Edition</Edition>
<ISBN>0-0672-32841-2</ISBN>
<Price>$40</Price>
</Book>
</Catalog>

5(B) Create file in notepad which contains the style sheet format for XML file, save
with “catalog_xsl.xsl”

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


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<center>
<h2>Books Information</h2>
<table border="1">
<tr bgcolor="gray"><th>TITLE</th>
<th>AUTHOR</th>
<th>PUBLICATION</th>
<th>ISBN</th>
<th>EDITION</th>
<th>PRICE</th>
</tr>
<xsl:for-each select="Catalog/Book">
<tr><td bgcolor="green"><xsl:value-of select="Title" /></td>
<td bgcolor="red"><b><xsl:value-of
select="translate(Author,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWX
YZ')" /></b></td>
<td bgcolor="cyan"><xsl:value-of select="Publication" /></td>
<td bgcolor="yellow"><xsl:value-of select="ISBN" /></td>
<td bgcolor="silver"><xsl:value-of select="Edition" /></td>
<td bgcolor="magenta"><xsl:value-of select="Price" /></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 Create an XML file which contain information about books and save with
“catalog.xml”

<?xml version="1.0" encoding="UTF-8" ?>


<?xml-stylesheet type="text/xsl" href="catalog_xsl.xsl" ?>
<Catalog>
<Book>
<Title>XML Bible</Title>
<Author>Winston</Author>
<Publication>Wiely</Publication>
<Edition>Fifth Edition</Edition>
<ISBN>0-7645-4760-7</ISBN>
<Price>$40.5</Price>
</Book>
<Book>
<Title>Artificial Intelegence</Title>
<Author>S.Russel</Author>
<Publication>Princeton Hall</Publication>
<Edition>Sixth Edition</Edition>
<ISBN>0-13-1038-5-2</ISBN>
<Price>$63</Price>
</Book>
<Book>
<Title>Java2</Title>
<Author>Watson</Author>
<Publication>BPB Publications</Publication>
<Edition>Third Edition</Edition>
<ISBN>0-41-1058-7-2</ISBN>
<Price>$60</Price>
</Book>
<Book>
<Title>HTML in 24 hours</Title>
<Author>Sam Peter</Author>
<Publication>SAM Publications</Publication>
<Edition>Fifth Edition</Edition>
<ISBN>0-0672-32841-2</ISBN>
<Price>$40</Price>
</Book>
</Catalog>
Output:
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. The color should also be changed if we change the color in the “property window “.

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

1. Create a Directory for the New Bean


create the directory C:\bdk1_1\demo\sunw\demo\colors. Then change to that
directory.

2. Create the Source File for the New Bean


Create the file and save it as Colors.java
// A simple Bean.
package sunw.demo.colors;
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;
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);
}
}
}

3. Compile the Source Code for the New


Bean Type the following command in command
prompt.
C:\bdk1_1\demo\sunw\demo\colors>java
c Colors.java

4. Create a Manifest File


You must now create a manifest file. First, switch to the
C:\bdk1_1\demo directory. This is the directory in which the manifest
files for the BDK demos are located. Put the
source code for your manifest file in the file colors.mft.
It is shown here:

5. Generate a JAR File


Beans are included in the ToolBox window of the BDK only if they are in
JAR files in the directory c:\bdk\jars. These files are generated with the
jar utility. Enter the following:
C:\bdk1_1\demo > jar cfm ..\jars\colors.jar colors.mft
sunw\demo\colors\*.class

This command creates the file colors.jar and places it in the directory
c:\bdk\jars.
6. Start the BDK
Change to the directory c:\bdk\beanbox> and type run. This causes the
BDK to start. You should see three windows, titled ToolBox, BeanBox, and
Properties. The ToolBox window should include an entry labeled “Colors”
for your new Bean.

7. Create an Instance of the Colors Bean (Testing)


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.
 Create and Configure an Instance of the OurButton Bean

Create an instance of the OurButton Bean in the BeanBox window. Then follow these
steps:

1. Go to the Properties window and change the label of the Bean to “Change”.You
should see that the button appearance changes immediately when this property is
changed.

2. Go to the menu bar of the BeanBox and select Edit | Events | action
|actionPerformed.

3. Move the cursor so that it is inside the Colors Bean display area, and click the
left mouse button. You should see the Event Target Dialog dialog box.

4. The dialog box allows you to choose a method that should be invoked when this
button is clicked. Select the entry labeled “change” and click the OK button. You
should see a message box appear very briefly, stating that the tool is “Generating
and compiling adaptor class.”

5. Click on the button. You should see the color change.


OUT PUT:
Week-7:

1) Install TOMCAT web server and APACHE.


While installation assign port number 4040 to TOMCAT and 8080 to APACHE.
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.
Accessthe pages by using the urls : http://localhost:4040/rama/books.html (for
tomcat)
http://localhost:8080/books.html (for Apache)

Installing Tomcat Server

While installing tomcat server on your PC you can either make use of Windows Installer
or you can download the package from using zip or tar files.

 Method 1.Installing Tomcat using Windows Installer

If you click on window installer then this program will automatically install tomcat web
server on your computer. When you start installation using this windows installer
program initially following window will appear.

click the Next button and the following screen will appear
you have to accept the terms by clicking the I Agree button

Just click Next button and the next window will appear on which the installation
directory can be chosen. If we want to change the default path you can click the browse
button and can change it. In this a folder created with the name Tomcat 5.5 on the C
drive and in that folder Tomcat server installed.

Then click the Next button and you will get the Configuration window. Here you can set
the connector port. By default the port is 8080 for Apache Tomcat Server. You can
change to any other value except the first 1024 values (The first 1024 port numbers are
reserved )
we can also set the user name and password for administration login. The click the Next
button

It will ask to select the JRE 5.0 path installed on our system.

After selecting the path click Install button ,then installation will start
At the end click the Finish button and the installation procedure gets completed.

After installing this software we need to configure it with the help of environment
variables. The configuration of Tomcat can be done using the following steps.

Step 1: First set the user environment variable JAVA_HOME. For that go to control
panel  System  Advanced tab. Click the Environment variables and set the
JAVA_HOME=C:\jdk1.5.0_15 (select the jdk home directory installed on the system)

step 2: Then set the environment variable for CATALINA_HOME as the Tomcat’s
directory. This environment variable is needed to start the Tomcat server.
Now you can start the Tomcat server by clicking the startup.bat batch file in the
C:\Tomcat 5.5\bin Directory or by giving the command at the command prompt as
follows.

 Method 2: Installing Tomcat using the Binary Distributions

Download the Tomcat from the web site http://tomact.apache.org/download-


55.cgi .For windows operating system choose option zip files and for Linux platform
chose tar.gz .

After extracting the binary distribution in the Tomcat 5.5 directory, we must set the
environment variable in the same way as in Method 1.
Now after starting up the Tomcat we must open the command prompt window and must
give the following commands.
After starting the Tomcat server the following window will appear on your compute

By default the tomcat server gets installed on the port 8080 but we can change the port
number. For instance if we want to change this port from 8080 to 4040 then we must go
to the directory C:\Tomcat 5.5\conf. Then there is an XML file named server.xml. For
editing this open this file it in Notepad.

 Find the following part


…….
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="4040" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value
to 0 -->
……..
and change the port=4040
now again go to the command prompt , start the Tomcat server by executing the
startup.bat command the following screen will appear.
Note the port number is getting
changed and now it is 4040

For stopping the Tomcat web server just press Control+c keys. Or type the
shutdown.bat command in command prompt.

 Testing Tomcat

To test the Tomcat web server we should open some web browser and enter this URL in
the address filed http://localhost:4040

Note that the by default the server name is localhost and we have set the port
4040(default port number is 8080). Following page gets displayed.
Installation of Apache web server on port 8080

Apache web server is an open source product and it is available on the internet. Get it
download from the site http://httpd.apache.org/download.cgi
Get the zip file with MSI installer (no_ssl) for downloading it on windows. Unzip it and
the installation procedure will start by appearing following window.

It will prompt for License Agreement. Just click on I accept .. and click Next button.
Click the next button

Click the next button


Click the next button
Select the Typical set up. Then the next window will display the default folder in which
the Apache will get installed. You can change it if you want by clicking change button.
Then click the Next button.

Then click the Install button. Finally you will get the installation complete message.
Hello Servlet Program

 The directory structure is

 Create a program in notepad and save with “hello.html”

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
<head>
<title>hello.html</title>
</head>
<body>
<form name="form1" action="./helloservlet" method="get">
<input type="submit" value="click here">
</form>
</body>
</html>

 Create a servlet program and save with “HelloServlet.java”

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html"); PrintWriter
out = response.getWriter();
out.print("<h2>Hello</h2> message from servlet");
out.close();
}

}
 Create a program in notepad and save with “web.xml”

<?xml version="1.0" encoding="UTF-8"?>


<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet</url-pattern>
</servlet-mapping>
</web-app>
Output:

The URL is http://localhost:8080/helloservlet/hello.html


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

Use init-parameters to do this. Store the user-names and passwords in the


webinf.xml and access them in the servlet by using the getInitParameters()
method.

Week 8(a):-Using Cookies concept

 Create a file in notepad and save with “login.html”

<html>
<head>
<title>login.html</title>
</head>
<body>
<form action="./getcookieservlet " method="post">
<table>
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" submit “></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>
 Create a file in notepad and save with “CookieServlet.java”

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie c1=new Cookie("user1","pass1");
Cookie c2=new Cookie("user2","pass2");
Cookie c3=new Cookie("user3","pass3");
Cookie c4=new Cookie("user4","pass4");
response.addCookie(c1);
response.addCookie(c2);
response.addCookie(c3);
response.addCookie(c4);
out.println("cookies are added");
out.close();
}

 Create a file in notepad and save with “GetCookieServlet.java”

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

public class GetCookieServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie[]c=request.getCookies();
Properties p=new Properties();
String cname,cvalue;
for(int i=0;i<c.length;i++){
cname=c[i].getName();
cvalue=c[i].getValue();
p.put(cname,cvalue);
}
String name,pass;
name=request.getParameter("uname");
pass=request.getParameter("pass");
if(p.containsKey(name))
{
if(pass.equals(p.getProperty(name)))
{ out.println("login sucessfull");
out.println("<br>welcome user");
out.println("<font size='18' color='green'>"+name+"</h2>");
}
els
e out.println("invalid password please try again");
}
else
{
out.println("invalid user name please try again");
}
out.close();
}
}
 Create a file in notepad and save with “web.xml”

<?xml version="1.0" encoding="UTF-8"?>


<web-app>
<servlet>
<servlet-name>CookieServlet</servlet-name>
<servlet-class>CookieServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>GetCookieServlet</servlet-name>
<servlet-class>GetCookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CookieServlet</servlet-name>
<url-pattern>/CS</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetCookieServlet</servlet-name>
<url-pattern>/getcookieservlet</url-pattern>
</servlet-mapping>
</web-app>
Output:

The URL is: http://localhost:8080/week8a/CS

The URL is : http://localhost:8080/week8a/login.html


Week 8(b) :-Using init-parameters

The directory structure is:


week8a \ login.html
WEB-INF\web.xml
\ classes\UserAuthenication.class

 Create a file in notepad and save with “UserAthentication.java”

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserAuthentication extends HttpServlet {

Properties p=new Properties();


public void init(ServletConfig sc)throws ServletException
{
super.init(sc);
Enumeration names=sc.getInitParameterNames();
String n,v;
while(names.hasMoreElements()){
n=names.nextElement().toString();
v=sc.getInitParameter(n);
p.put(n,v);
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws
ServletException,IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name,pass;
name=request.getParameter("uname").trim();
pass=request.getParameter("pass").trim();

if(p.containsKey(name))
{
if(pass.equals(p.getProperty(name)))
{
out.println("login successful<br>");
out.println("welcome <font color='green'
size='15'>"+name+"</font>");
}
else
out.print("invalid password");
}
else
out.println("invalid username");
out.close();
}
}
 Create a file in notepad and save with “login.html”

<html>
<head>
<title>login.html</title>
</head>
<body>
<form action="./UA" method="post">
<table>
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" submit “></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>

 Create a file in notepad and save with “web.xml”

<?xml version="1.0" encoding="UTF-8"?>


<web-app>
<servlet>
<servlet-name>UserAuthentication</servlet-name>
<servlet-class>UserAuthentication</servlet-class>
<init-param>
<param-name>user1</param-name>
<param-value>pass1</param-value>
</init-param>
<init-param>
<param-name>user2</param-name>
<param-value>pass2</param-value>
</init-param>
<init-param>
<param-name>user3</param-name>
<param-value>pass3</param-value>
</init-param>
<init-param>
<param-name>user4</param-name>
<param-value>pass4</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>UserAuthentication</servlet-name>
<url-pattern>/UA</url-pattern>
</servlet-mapping>
</web-app>
Output:

The URL is http://localhost:8080/week8b/login.html


JDBC program for retrieving information from student table

 Create table with the following command

SQL> create table student(rno number(5),name varchar2(20),percentage


number(5,2));

 Write a jdbc program in notepad and save with “jdbctest.java”

import java.io.*;
import java.sql.*;
public class jdbctest
{
public static void main(String[] args) throws Exception
{

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select *from student");
System.out.println("rno \t name \t percentage(%)\n");
while(rs.next())
{ System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getDo

uble(3));

}
}

Output:
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).
Practice 'JDBC' connectivity.
Write a java program/servlet/JSP to connect to that database and extract
data from the tables and display them. Experiment with various SQL queries.
Insert the details of the users who register with the web site, whenever a new
user clicks the submit button in the registration page (week2).

The directory structure is:


Week9 \ registration.html
WEB-INF\web.xml
\ classes\RegServlet.class

 Create the table in database with the name “registration”

CREATE TABLE REGISTRATION( REGID


NUMBER(5),
NAME VARCHAR2(20),
PASSWORD VARCHAR2(20),
PHNO VARCHAR2(10),
EMAIL VARCHAR2(20),
GENDER VARCHAR2(10),
DOB VARCHAR2(20),
LANGUAGES VARCHAR2(30),
ADDRESS VARCHAR2(100) );

 Create a program in notepad and save with “registration.html”

<html>
<head>
<title>registration.html</title>
</head>
<body>
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./regservlet" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="emai" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>&nbsp;
month&nbsp;&nbsp; <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>&nbsp;&nbsp;
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU&nbsp;&nbsp; <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI&nbsp; &nbsp;
&nbsp;&nbsp; <input type="checkbox" name="hindi" value="hindi"> </td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="submit" align="center" value="send">&nbsp;<input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>

 Create servlet program and save with “RegServlet.java”

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RegServlet extends HttpServlet {

Connection conn=null;
Statement stmt=null;
PreparedStatement pstmt=null;
ResultSet rs=null;

public void init()throws ServletException{


try{

Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
stmt=conn.createStatement();
pstmt=conn.prepareStatement("INSERT INTO REGISTRATION
VALUES(?,?,?,?,?,?,?,?,?)");

}
catch(Exception e)
{ System.out.println("error:"+e.toString()
);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

try{

conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
conn.setAutoCommit(false);
rs=stmt.executeQuery("SELECT MAX(REGID) FROM REGISTRATION");
int regid;
if(rs.next()){
regid=rs.getInt(1);
}
else{
regid=0;
}

regid++; pstmt.setInt(1,regid);
pstmt.setString(2,request.getParameter("name").trim());
pstmt.setString(3,request.getParameter("pass").trim());
pstmt.setString(4,request.getParameter("phno").trim());
pstmt.setString(5,request.getParameter("email").trim());
pstmt.setString(6,request.getParameter("gender").trim());

String dob;

dob=request.getParameter("day")+"/"+request.getParameter("month")+"/"+request.get
Parameter("year");

String languages;

languages=request.getParameter("telugu")+","+request.getParameter("english")+","+re
quest.getParameter("hindi");

pstmt.setString(7,dob); pstmt.setString(8,languages);
pstmt.setString(9,request.getParameter("address").trim());
int i=pstmt.executeUpdate();

if(i==1)
{
conn.commit();
out.println("Registration is successful </br> your regid is " );
out.println("<font color='green' size='4'>"+regid+"</font>");
}
else{ conn.rollback();
out.println("<h2 color='red'>registration is fail</h2>");

}
}

catch(Exception e){
out.println(e);
}
out.close();
}

public void destroy(){


try{
c
o
n
n
.
c
l
o
s
e
(
)
;
s
t
m
t
.
c
l
o
s
e
(
)
;
p
s
t
m
t
.
c
l
o
s
e
(
)
;
}
catch(Exception e){
e.printStackTrace();
}
}
}

 Create a file in notepad and save with “web.xml”

<?xml version="1.0" encoding="UTF-8"?>


<web-app >
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>RegServlet</servlet-name>
<servlet-class>RegServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegServlet</servlet-name>
<url-pattern>/regservlet</url-pattern>
</servlet-mapping>
</web-app>
Output:

The URL is http://localhost:8080/week9/registration.html


JSP <jsp:useBean> program

 Create file in notepad and save with “usebean_page.jsp” under “C:\Tomcat


5.5\webapps\ROOT” directory.

<%@ page import="java.util.*" %>


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body bgcolor="white">
<jsp:useBean id="clock" class="java.util.Date" />
<c:choose>
<c:when test="${clock.hours < 12}">
<h1>Good morning!</h1>
</c:when>
<c:when test="${clock.hours < 18}">
<h1>Good day!</h1>
</c:when>
<c:otherwise>
<h1>Good evening!</h1>
</c:otherwise>
</c:choose>
welcome to our site, open 24 hours a day.
</body>
</html>

Output:
The URL is http://localhost:8080/usebean_page.jsp
Week-10:

Write a JSP which does the following job:


Insert the details of the 3 or 4 users who register with the web site (week9) by using
registration form. Authenticate the user when he submits the login form using the user
name and password from the database (similar to week8 instead of cookies).

 Create a table with name registration1

Create table registration1(name varchar2(20),pass varchar2(20),phno


varchar2(10),email varchar2(20));

 Create the file save with “registration.html”

<html>
<head>
<title>registration.html</title>
</head>
<body>
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./registration.jsp" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="email" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>&nbsp;
month&nbsp;&nbsp; <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>&nbsp;&nbsp;
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU&nbsp;&nbsp; <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI&nbsp; &nbsp;
&nbsp;&nbsp; <input type="checkbox" name="hindi" value="hindi"> </td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="submit" align="center" value="send">&nbsp;<input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>

 Create the file and save with “registration.jsp”


<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*" %>
<%
String name=request.getParameter("name");
String pass=request.getParameter("pass");
String phno=request.getParameter("phno");
String email=request.getParameter("email");
int i=0;

try{ Class.forName("oracle.jdbc.driver.OracleDriv
er");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
PreparedStatement pstmt=conn.prepareStatement("INSERT INTO REGISTRATION1
VALUES(?,?,?,?)");

pstmt.setString(1,name);
pstmt.setString(2,pass);
pstmt.setString(3,phno);
pstmt.setString(4,email);

i=pstmt.executeUpdate();
pstmt.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
<html>
<body>
<% if(i==1)
out.println("<h3 color='green'>Registation is successful</h3>");
else
out.println("<h3 color='red'>Registration fail</h3>"); %>
</body>
</html>

 Create the file and save with “login.html”

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
<head>
<title>login.html</title>
</head>
<body>
<h3 align="center">login form</h3>
<form action="./login.jsp" method="post">
<table align="center">
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" submit "></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>

 Create the file and save with “login.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<%
Boolean valid=false;
String name=request.getParameter("uname");
String pass=request.getParameter("pass");
try{

Class.forName("oracle.jdbc.driver.OracleDriver"); Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT name,pass FROM REGISTRATION1");

while(rs.next()){
if(name.equals(rs.getString("name"))&&pass.equals(rs.getString("pass")))
{
valid=true;
break;
}
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
out.println(e.toString());
}
%>
<html>
<body>
<% if(valid){ %>
<h2 color="yellow">login sucessfull</h2><br>
<h3><% out.println("welcome user <font color='green'>"+name+"</font>");%>
<%}else{ %>
<h2 color="yellow">login fail invalid username/password</h2>
try again <a href="http://localhost:8080/week10/login.html">click here</a>
<%} %>
</body>
</html>
Output:

The URL is http://localhost:8080/week10/registration.html


The URL is http://localhost:8080/week10/login.html
Week-11:

Create tables in the database which contain the details of items (books in our
case like Book name , Price, Quantity, Amount )) of each category. Modify your
catalogue page (week 2)in such a way that you should connect to the database
and extract data from the tables and display them in the catalogue page using
JDBC.

 The directory structure is

 Create the following tables in the database

Create table catalog_books(name varchar2(20),author varchar2(20),publication


varchar2(20),price varchar2(20));

Create table cse_books(name varchar2(20),author varchar2(20),publication


varchar2(20),price varchar2(20));

Create table ece_books(name varchar2(20),author varchar2(20),publication


varchar2(20),price varchar2(20));

Create table eee_books(name varchar2(20),author varchar2(20),publication


varchar2(20),price varchar2(20));

Create table mech_books(name varchar2(20),author varchar2(20),publication


varchar2(20),price varchar2(20));

 Insert some books information into the above tables


insert into catalog_books values('AI','S.Russel','Princeton','$63');
insert into catalog_books values('HTML in 24 hours','Sam Peter','Sam
publications','$50');
insert into catalog_books values('XML BIBLE','WINSTON','WIELY','$40.2');
insert into catalog_books values('JAVA2','WATSON','BPB','$35.5');

 Create the file and save with “catalog.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<html>
<body>
<h3 align="center">catalogue page</h3>
<%
try{ Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *FROM catalog_books");

%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#123456"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e)
{ out.println(e.toString()
);
} %>
</body>
</html>

 Create the file and save with “csebooks.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<html>
<body>
<h2 align="center">CSE BOOKS CATALOGUE PAGE</h2>
<%
try{ Class.forName("oracle.jdbc.driver.OracleDriv
er"); Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *FROM CSE_BOOKS");
%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#ffdcba"> <td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e){
out.println(e.toString());
} %>
</body>
</html>

 Create the file and save with “ ecebooks.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<html>
<body>
<h2 align="center">ECE BOOKS CATALOGUE PAGE</h2>
<%
try{ Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *FROM ECE_BOOKS");

%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e){
out.println(e.toString());
} %>
</body>
</html>
 Create the file and save with “ eeebooks.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<html>
<body>
<h2 align="center">EEE BOOKS CATALOGUE PAGE</h2>
<%
try{ Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *FROM EEE_BOOKS");

%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e){
out.println(e.toString());
} %>
</body>
</html>

 Create the file and save with “ mechbooks.jsp”

<%@ page language="java" import="java.sql.*" pageEncoding="ISO-8859-1"%>


<%@ page import="java.io.*" %>
<html>
<body>
<h2 align="center">MECHANICAL BOOKS CATALOGUE PAGE</h2>
<%
try{ Class.forName("oracle.jdbc.driver.OracleDriver
");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT *FROM MECH_BOOKS");

%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e)
{ out.println(e.toString()
);
} %>
</body>
</html>
Output:

The URL is http://localhost:8080/week11/book.html


Program on session management in servlets

 Create a file in notepad and save with “home.html”

<html>
<head><title>home</title>
</head>
<body>
<form action="./dateservlet" method="get">
<input type="submit" value="click">
</form>
</body>
</html>

 Create a servlet program, in which session is created by using getSession () method


of HttpsServletRequest. An HttpSession object is returned. This object can store set
of bindings that associated with names with objects. The setAttribute (), getAttribute
(), getAttributeNames () and removeAttribute () methods can be used to manage
these bindings. Save the file with “DateServlet.java”

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{ HttpSession hs =
request.getSession(true);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("<B>");
// Display date/time of last access.
Date date = (Date)hs.getAttribute("date");
if(date != null) {
pw.print("Last access: " + date + "<br>");
}
// Display current date/time.
date = new Date();
hs.setAttribute("date", date);
pw.println("Current date: " + date);
}
}

 Create deployment descriptor file “web.xml”

<?xml version="1.0" encoding="UTF-8"?>


<web-app>
<servlet>
<servlet-name>DateServlet</servlet-name>
<servlet-class>DateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DateServlet</servlet-name>
<url-pattern>/dateservlet</url-pattern>
</servlet-mapping>
</web-app>
Output:

The URL is http://localhost:8080/servlet_session/home.html


WEEK 11:
JSP Source Code for Basic Arithmetic Example

<html>
<head>
<title>JSP 2.0 Expression Language - Basic Arithmetic</title>
</head>
<body>
<h1>JSP 2.0 Expression Language - Basic Arithmetic</h1>
<hr>
This example illustrates basic Expression Language arithmetic.
Addition (+), subtraction (-), multiplication (*), division (/ or div),
and modulus (% or mod) are all supported. Error conditions, like
division by zero, are handled gracefully.
<br>
<blockquote>
<code>
<table border="1">
<thead>
<td><b>EL Expression</b></td>
<td><b>Result</b></td>
</thead>
<tr>
<td>\${1}</td>
<td>${1}</td>
</tr>
<tr>
<td>\${1 + 2}</td>
<td>${1 + 2}</td>
</tr>
<tr>
<td>\${1.2 + 2.3}</td>
<td>${1.2 + 2.3}</td>
</tr>
<tr>
<td>\${1.2E4 + 1.4}</td>
<td>${1.2E4 + 1.4}</td>
</tr>
<tr>
<td>\${-4 - 2}</td>
<td>${-4 - 2}</td>
</tr>
<tr>
<td>\${21 * 2}</td>
<td>${21 * 2}</td>
</tr>
<tr>
<td>\${3/4}</td>
<td>${3/4}</td>
</tr>
<tr>
<td>\${3 div 4}</td>
<td>${3 div 4}</td>
</tr>
<tr>
<td>\${3/0}</td>
<td>${3/0}</td>
</tr>
<tr>
<td>\${10%4}</td>
<td>${10%4}</td>
</tr>
<tr>
<td>\${10 mod 4}</td>
<td>${10 mod 4}</td>
</tr>
<tr>
<td>\${(1==2) ? 3 : 4}</td>
<td>${(1==2) ? 3 : 4}</td>
</tr>
</table>
</code>
</blockquote>
</body>
</html>
OUTPUT:

JSP 2.0 Expression Language - Basic Arithmetic

EL Expression Result

${1} 1

${1 + 2} 3

${1.2 + 2.3} 3.5

${1.2E4 + 1.4} 12001.4

${-4 - 2} -6

${21 * 2} 42

${3/4} 0.75

${3 div 4} 0.75

${3/0} Infinity

${10%4} 2

${10 mod 4} 2

${(1==2) ? 3 : 4} 4

WEEK 12:
WRITE A JAVASCRIPT SCRIPT FOR SELECTION SORT.
PROGRAM
<html>
<head>
<title> Sort</title>
<script language="Javascript">
var b,i,j,temp;
var a;
a=[];
document.write("Enter array");
for(i=0;i<5;i++)
{
b=prompt("enter array element=","0");
a[i]=parseInt(b);
}
for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
document.write("<br>Sorted array is");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]<a[j])
{
temp=a[i]; a[i]=a[j]; a[j]=temp;
} } }

for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
</script> </head></html>

OUTPUT

Enter array 4 2 5
Sorted array is 2 4 5

You might also like