Web Technologies Lab Manual

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 107
At a glance
Powered by AI
The key takeaways from the lab manual are that students will learn how to design static and dynamic web pages for an online bookstore using HTML, CSS, JavaScript and JSP. They will learn how to create pages like home, login, catalog, cart and registration pages and add validation to the registration form.

The main topics covered in the lab manual include designing static web pages for a bookstore website, adding validation to forms using JavaScript, using CSS for styling, and inserting/retrieving data to/from a database using JSP.

The different static web pages that need to be designed are the home page with three frames, login page, catalog page to display book details in a table, cart page to show items in cart and a registration page.

WEB TECHNOLOGIES LAB

MANUAL

DEPARTMENT OF INFORMATION
TECHNOLOGY
WEB TECHNOLOGIES LAB MANUAL
Prepared by: A.P.V.D.L.Kumar, B.Tech,

(M.Tech), Asst. Professor

R07 (3rd YEAR IT)

B V C INSTITUTE OF TECHNOLOGY AND SCIENCE


AMALAPURAM
(Affiliated to JNTU, Kakinada, Approved by AICTE New Delhi)

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
1

WEB TECHNOLOGIES LAB


MANUAL

WEB TECHNOLOGIES LAB SYLLABUS


WEEK-1:
Design the following static web pages required for an online book store web site.
1) HOME PAGE:
The static home page must contain three frames.
Top frame : Logo and the college name and links to Home page, Login page, Registration
page, Catalogue page and Cart page (the description of these pages will be given below).
Left frame : At least four links for navigation, which will display the catalogue of respective
links.
For e.g.: When you click the link CSE the catalogue for CSE Books should be
displayed in the Right frame.
Right frame: The pages to the links in the left frame must be loaded here. Initially this page
contains description of the web site.
2) LOGIN PAGE:
It contains the fields Login, Password text boxes and submit, reset buttons.
3) CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the web site in a
table. The details should contain the following:
1. Snap shot of Cover Page.
2. Author Name.
3. Publisher.
4. Price.
5. Add to cart button.
WEEK-2:
4) CART PAGE:
The cart page contains the details about the books which are added to the cart.
The cart page contains the fields: Book, name, Price, Quantity and Amount
5) REGISTRATION PAGE:
Create a registration form with the following fields
1) Name (Text field)
2) Password (password field)
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
2

3) E-mail id (text field)

WEB TECHNOLOGIES LAB


MANUAL

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)
WEEK 3:
VALIDATION:
Write JavaScript to validate the following fields of the above 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).
Note: You can also validate the login page with these parameters.
WEEK-4:
Design a web page using CSS (Cascading Style Sheets) which includes the following:
1) Use different font, styles:
In the style definition you define how each selector should work (font, color etc.).
Then, in the body of your pages, you refer to these selectors to activate the styles.
2) Set a background image for both the page and single elements on the page.
You can define the background image for the page like this:
3) Control the repetition of the image with the background-repeat property.
As background-repeat: repeat
Tiles the image until the entire page is filled, just like an ordinary background image in
plain HTML.
4) Define styles for links as
A:link
A:visited
A:active
A:hover
Example:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
3

<style type="text/css">

WEB TECHNOLOGIES LAB


MANUAL

A:link {text-decoration: none}


A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: underline; color: red;}
</style>
5) Work with layers:
For example:
LAYER 1 ON TOP:
<div style="position:relative; font-size:50px; z-index:2;">LAYER 1</div>
<div style="position:relative; top:-50; left:5; color:red; font-size:80px; zindex:
1">LAYER 2</div>
LAYER 2 ON TOP:
<div style="position:relative; font-size:50px; z-index:3;">LAYER 1</div>
<div style="position:relative; top:-50; left:5; color:red; font-size:80px; zindex:
4">LAYER 2</div>
6) Add a customized cursor:
Selector {cursor:value}
WEEK-5:
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.
Display 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. Use XML schemas XSL and CSS for
the above purpose.
Note: Give at least for 4 books. It should be valid syntactically.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
4

WEB TECHNOLOGIES LAB


Hint: You can use some xml editors like XML-spy
MANUAL
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 .
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.
Access the pages by using the urls : http://localhost:4040/rama/books.html (for tomcat)
http://localhost:8080/books.html (for Apache)
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 ids 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-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
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
5

WEB TECHNOLOGIES LAB


tables and display them. Experiment with various
SQL queries.
MANUAL
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).
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).
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.
WEEK-12:
HTTP is a stateless protocol. Session is required to maintain the state.
The user may add some items to cart from the catalog page. He can check the cart page for
the selected items. He may visit the catalogue again and select some more items. Here our
interest is the selected items should be added to the old cart rather than a new cart. Multiple
users can do the same thing at a time(i.e., from different systems in the LAN using the ipaddress instead of localhost). This can be achieved through the use of sessions. Every user
will have his own session which will be created after his successful login to the website.
When the user logs out his session should get invalidated (by using the method
session.invalidate() ). Modify your catalogue and cart JSP pages to achieve the above
mentioned functionality using sessions.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
6

WEB TECHNOLOGIES LAB


MANUAL
OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
7

WEB TECHNOLOGIES LAB


MANUAL
WEEK 1:
AIM:- Design the following static web pages required for an online book store web
site.
1) HOME PAGE:
The static home page must contain three frames. Top frame : Logo and the college
name and links to Home page, Login page, Registration page,
Catalogue page and Cart page (the description of these pages will be given below).
Left frame : At least four links for navigation, which will display the catalogue of
respective links.
For e.g.: When you click the link IT the catalogue for IT Books should be
displayed in the Right frame. Right frame: The pages to the links in the left
frame must be loaded here. Initially this page contains
description of the web site.
<!Program for Creating home page with three frames(Homepage.html)-->
<html>
<head>
<title>HOME PAGE </title>
</head>
<frameset rows="20%,*" border="0">
<frame src="Topframe.html" noresize=noresize scrolling="no" color="grey">
<frameset cols="8%,*">
<frame src="Leftframe.html" noresize=noresize scrolling="no">
<frame src="RightFrame.html" noresize="noresize" name="showframe">
</frameset>
</frameset>
</html>

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
8

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
9

WEB TECHNOLOGIES LAB


MANUAL
<!Creating top frame it contains Logo and the college name and links to Home page,
Login page, Registration page, Catalogue page and Cart page (Topframe.html)-->
<html>
<head>
<title>TOP FRAME</title>
</head>
<body bgcolor="#67521">
<img src="F:\APVDL KUMAR\WEEK1,2\logo1.jpg" align=left width=70 height=70>
<h1 align="center"><font color="ff00ff"><marquee>ONLINE BOOK
STORE</marquee></font></h1>
<table cellspacing="1" cellpadding="1" align="center" width="90%" border="1">
<tr>
<th align="center"><a href ="RightFrame.html" target ="showframe"><font
color="yellow">Home</font></a></td>
<th align="center"><a href ="Login.html" target ="showframe"><font
color="yellow">Login</font></a></td>
<th align="center"><a href ="Regform.html" target ="showframe"><font
color="yellow">Registration</font></a></td>
<th align="center"><a href ="Catalogue.html" target ="showframe"><font
color="yellow">Catalogue</font></a></td>
<th align="center"><a href ="Cart1.html" target ="showframe"><font
color="yellow">Cart</font></td>
</tr>
</table>
</body>
</html>

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
10

10

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT: (Leftframe.html)

OUTPUT: (RightFrame.html)

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
11

11

WEB TECHNOLOGIES LAB


MANUAL

<!Program for creating Left frame it contains at least four links for navigation, which
will display the catalogue of respective links(Leftframe.html)-->
<html>
<body fontsize="5" bgcolor=#85697 >
<center>
<a href="cse.html" target=showframe><h2>CSE</h2></a><br><br>
<a href="ece.html" target=showframe><h2>ECE</h2></a><br><br>
<a href="eee.html" target=showframe><h2>EEE</h2></a><br><br>
<a href="civil.html" target=showframe><h2>CIVIL</h2></a><br><br>
</body>
</center>
</html>

<!Program for creating Right frame: The pages to the links in the left frame must be
loaded here. Initially this page contains description of the web site(RightFrame.html)-->

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
12

12

WEB TECHNOLOGIES LAB


MANUAL
<body bgcolor="#29897">
<h2 align="center"><font color="pink">WELCOME TO ONLINE
SHOPEE</font></h2>
</body>
</html>
<html>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
13

13

WEB TECHNOLOGIES LAB


MANUAL

<!Program for creating the login page it contains the fields Login, Password text
boxes and submit, reset buttons. (Login.html)-->
<html>
<head>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
14

14

WEB TECHNOLOGIES LAB


<title>LOGIN</title>
MANUAL
</head>
<body align="center" bgcolor="#9876">
<h3 align="center">LOG IN PAGE</h3>
<table align="center" height="20%">
<tr>
<td align="right">LOGIN-ID:</td>
<td align="left"> <input type="text" maxlength="30" size="20"></td>
</tr>
<tr>
<td align="right">PASSWORD:</td>
<td align="left"><input type="password" maxlength="30" size="20"></td>
</tr>
<tr>
<td></td>
<td><font color="black"><a href="Regform.html">New User Click
here</font></a></td>
</tr>
<tr>
<td></td>
<td align="left"><input type="SUBMIT" value="SUBMIT"></td>
<td align="left"><input type="RESET" value="RESET"> </td>
</tr>
</table>
</body>
</html>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
15

15

WEB TECHNOLOGIES LAB


MANUAL

<!Program for creating the Catalogue page should contain the details of all the books
available in the web site in a table. The details should contain the following: 1. Snap shot

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
16

16

WEB TECHNOLOGIES LAB


of Cover Page 2. Author Name 3. Publisher
4. Price 5. Add to cart button
MANUAL
(Catalogue.html)-->
<html>
<head> <title>Catalogue</title></head>
<body bgcolor="#16789">
<table align="center" border="1" width="100%" height="100%">
<tr>
<td align="center"><img src="xml.jpg" width=60 height=60 alt="" /></td>
<td align="left"><p>Book: XML Bible</p><p>Author:
Winston</p><p>Publication: Wiely</p></td>
<td>
<table width="60%" align="center">
<tr>
<td align="left">$63</td>
<td align="right"><input type="button" value="ADD TO CART"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center"><img src="ai.jpg" alt="" width="60" /></td>
<td align="left"><p>Book: AL</p><p>Author: S.Russel</p><p>Publication:
Princeton hall</p></td>
<td>
<table width="60%" align="center">
<tr>
<td align="left">$63</td>
<td align="right"><input type="button" value="ADD TO CART"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center"><img src="java2.jpg" width=60 height=60 alt="" /></td>
<td align="left"><p>Book: Java 2</p><p>Author:
Watson</p><p>Publication:
BPB Publications</p></td>
<td>
<table width="60%" align="center">
<tr>
<td> </td>
<td align="left">$35.5</td>
<td align="right"><input type="button" value="ADD TO CART"/></td>
<td></td>
</tr>
</table>
</td>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
17

17

</tr>
<tr>

WEB TECHNOLOGIES LAB


MANUAL
<td align="center"><img src="html.jpg" width=60 height=60 alt="" /></td>
<td align="left"><p>Book: HTML in 24 hours</p><p>Author: Sam
Peter</p><p>Publication: Sam Publications</p></td>

<td>
<table width="60%" align="center">
<tr>
<td></td>
<td align="left">$63</td>
<td align="right"><input type="button" value="ADD TO CART"/></td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
18

18

WEB TECHNOLOGIES LAB


MANUAL

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
19

19

WEB TECHNOLOGIES LAB


WEEK2:
MANUAL
AIM: Creating the cart page and registration pages.
<!Program for creating a CART page contains the details about the books which are
added to the cart.The cart page contains the fields: Book, name, Price, Quantity and
Amount (cart1.html)-->
<html>
<body bgcolor=#45678>
<table cellspacing="50" cellpadding="20">
<tr>
<td>Book name</td>
<td>price</td>
<td>quantity</td>
<td>amount</td>
</tr>
<tr>
<td>java2</td>
<td>$35.5</td>
<td>2</td>
<td>$70</td>
</tr>
<tr>
<td>XML bible</td>
<td>$40.5</td>
<td>1</td>
<td>$40.5</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Total amount </td>
<td>130.5 </td>
</tr>
</body>
</html>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
20

20

WEB TECHNOLOGIES LAB


MANUAL

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
21

21

WEB TECHNOLOGIES LAB


<!Program for Creating a registration
form with the following fields 1) Name (Text
MANUAL
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) (Regform.html)-->
<html>
<head>
<title>REGISTRATION FORM</title>
</head>
<body bgcolor="#2456">
<h2 align="center">ONLINE REGISTRATION</h2>
<hr align="center" width="100%" />
<p align="center"><font color="red"><sup>*</sup>indicates mandatory field</font></p>
<table align="center" cellspacing="12">
<tr>
<td align="right">First name:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="fname">
</tr>
<tr>
<td align="right">Last name:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="lname">
</tr>
<tr>
<td align="right">PassWord:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="PassWord" maxlength="40" size="35" name="pw">
</tr>
<tr>
<td align="right">Confirm PassWord:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="PassWord" maxlength="40" size="35" name="cp">
</tr>
<tr>
<td align="right">Gender:</td>
<form>
<td><input type="radio" name="sex" value="male" /> Male
<input type="radio" name="sex" value="female" /> Female</td>
</form>
</tr>
<tr>
<td align="right">DATE OF BIRTH:</td>
<td align="left">
<select name="dob">
<option value="x">Month</option>
<option value="j">JAN</option>
<option value="f">FEB</option>
<option value="m">MAR</option>
<option value="A">APR</option>
<option value="m">MAY</option>
<option value="j">JUN</option>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
22

22

WEB TECHNOLOGIES LAB


<option value="j">JUL</option>
MANUAL
<option value="j">AUG</option>
<option value="v">SEP</option>
<option value="o">OCT</option>
<option value="n">NOV</option>
<option value="d">DEC</option>
</select>
<select name="dob1">
<option value="v">DAY</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="c">10</option>
<option value="x">11</option>
<option value="a">12</option>
<option value="q">13</option>
<option value="f">14</option>
<option value="o">15</option>
<option value="s">16</option>
<option value="y">17</option>
<option value="z">18</option>
<option value="i">19</option>
<option value="j">20</option>
<option value="h">21</option>
<option value="e">22</option>
<option value="u">23</option>
<option value="e">24</option>
<option value="c">25</option>
<option value="b">26</option>
<option value="v">27</option>
<option value="p">28</option>
<option value="o">29</option>
<option value="k">30</option>
<option value="c">31</option>
</select>
<select name="dob3">
<option value="ram">YEAR</option>

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
23

23

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
24

24

WEB TECHNOLOGIES LAB


MANUAL

<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
</select>
<tr>
<td align="right">Email-ID:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="ename">
</tr>
<tr>
<td align="right">Phone number:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="phn">
</tr>
<tr>
<td align="right">Languages known:</td>
<td align="left"><input type="checkbox" name="hb" value="en">English</td>
<td align="left"><input type="checkbox" name="hb" value="te">Telugu</td>
</tr>
<tr>
<td></td>
<td align="left"><input type="checkbox" name="hb" value="hi">Hindi</td>
<td align="left"><input type="checkbox" name="hb" value="ta">Tamil</td>
</tr>
<tr>
<td align="right">Address:<font color="red"><sup>*</sup></font></td>
<td align="left"><textarea rows="6" cols="20" name="add">
</textarea> </td>
</tr>
<tr>
<td align="right">About us:</td>
<td align="left"><textarea rows="8" cols="30" name="abu"></textarea> </td>
</tr>
<tr>
<td></td>
<td align="left"><input type="checkbox" name="xx" value="yy">I Agree with terms and
Conditions</td>
</tr>
<tr> <td></td>
<td align="left"><input type="SUBMIT" value="SUBMIT"></td>
<td align="right"><input type="RESET" value="RESET"></td>
</tr>
</table>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
25

25

WEB TECHNOLOGIES LAB


MANUAL

</body>

OUTPUT: (cse.html)

OUTPUT: (ece.html)

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
26

26

WEB TECHNOLOGIES LAB


MANUAL

<!--link code for CSE, it shows CSE Books should be displayed in the Right
frame(cse.html)-->
<html>
<body bgcolor=pink>
<h1><center>CSE TEXTBOOKS</center>
<img src="F:\APVDL KUMAR\WEEK1,2\ai.jpg"><b>THIS IS AI TEXTBOOK</b></h1>
</body>
</html>
<!--link code for ECE, it shows ECE Books should be displayed in the Right
frame(ece.html)-->
<html>
<body bgcolor="#E9CFEC">
<center><B><H1>ECE TEXTBOOKS</H1></B></center>
<img src="F:\APVDL KUMAR\WEEK1,2\ece.jpg" width=100>
<b>THIS IS ECE TEXTBOOK</b>
</body>
</html>
<!--link code for EEE, it shows EEE Books should be displayed in the Right
frame(eee.html)-->
<html>
<body bgcolor="#8EEBEC">
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
27

27

WEB TECHNOLOGIES LAB


<CENTER><B><H1>EEE TEXTBOOKS</H1></B></CENTER>
MANUAL
<img src=" F:\APVDL KUMAR\WEEK1,2\eee.jpg"><B>THIS IS EEE BOOK</B>
</body>
</html>
<!--link code for CIVIL, it shows CIVIL Books should be displayed in the Right
frame(civil.html)-->
<html>
<body bgcolor="#F778A1"><CENTER><B><H1>CIVIL
TEXTBOOKS</H1></B></CENTER>
<h1>
<img src=" F:\APVDL KUMAR\WEEK1,2\civil.jpg">
<B>THIS IS CIVIL TEXTBOOK</B></h1>
</body>
</html>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
28

28

WEB TECHNOLOGIES LAB


MANUAL

WEEK 3:
AIM: VALIDATION:
Write JavaScript to validate the following fields of the above registration page.
2. 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).
Note: You can also validate the login page with these parameters.
<!Program for validating the username (Name should contains alphabets and the
length should not be less than 6 characters)(uservalid.html) -->
<html>
<head>
<title>validating a textbox</title>
<script language="javascript">
function button_click()
{
var fname=f.fname.value;
var spchar = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~";
if(fname.length<6)
{
alert("first name atleast 6 characters");
}
if(fname!="")
{
for (var i=0;i<fname.length;i++)
{
if(spchar.indexOf(fname.charAt(i)) != -1)
{
alert ("Userid should not have special characters");
f.fname.value="";
f.fname.focus();
return false;
}
}
}
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
29

29

if(fname.length>=6)
alert("valid username");

WEB TECHNOLOGIES LAB


MANUAL

}
</script>
<body>
<center>
<form name="f">
<table>
<h2 align="center">USER NAME VALIDATION</h2>
<tr>
<td align="right">USERNAME:</td>
<td><input type="text" name="fname" maxlength=20 size=30></td>
</tr>
<br>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
30

30

WEB TECHNOLOGIES LAB


MANUAL

<tr>
<td></td>
<td><input type="button" value="SUBMIT" onClick="button_click()"></td></tr>
</form>
</table>
</center>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
31

31

WEB TECHNOLOGIES LAB


MANUAL

</body>
</html>

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
32

32

WEB TECHNOLOGIES LAB


MANUAL

<!--Program for password field validation(should not be less than 6 characters)


(pwdvalid.html)-->
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
33

33

WEB TECHNOLOGIES LAB


<html>
MANUAL
<head>
<title>PASSWORD VALIDATION</title>
<script language="javascript">
function pass()
{
var pw=f.pw.value;
var cpw=f.cpw.value;
if(pw.length<6)
{
alert("PASSWORD MUST BE 6 CHARACTERS");
}
if(pw!=cpw)
{
alert("PASSWORD DON'T MATCH");
}
else if(pw.length>=6)
alert("PASSWORD VALIDATION SUCCESS");
}
</script>
</head>
<body>
<form name="f">
<table align="center">
<h2 align="center">PASSWORD VALIDATION</h2>
<br>
<tr>
<td align="right">PassWord:</td>
<td align="left"><input type="PassWord" maxlength="10" size="30"
name="pw"></td>
</tr>
<tr>
<td align="right">Confirm PassWord:</td>
<td align="left"><input type="PassWord" maxlength="10" size="30"
name="cpw"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="SUBMIT" onClick="pass()"/></td>
</tr>
</table>
</form>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
34

34

WEB TECHNOLOGIES LAB


MANUAL

<!Program for E-mail id validation(should not contain any invalid and must follow
the standard pattern-)(emailvalid.html)-->
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
35

35

WEB TECHNOLOGIES LAB


<html>
MANUAL
<head>
<title>EMAIL ID VALIDATION</title>
<script language="javascript">
function check()
{
if(f.txtname.value.indexOf('@')==-1)
{
alert("invalid");
}
else if((f.txtname.value.indexOf('@')==0) ||(f.txtname.value.indexOf('.')==0)||
(f.txtname.value.indexOf('@'))>
(f.txtname.value.indexOf('.')))
{
alert("invalid email id");
f.txtname.value="";
f.txtname.focus();
}
else
alert("valid email id");
}
</script>
</head>
<body>
<form name="f">
<table align="center">
<h2 align="center">EMAIL VALIDATION</h2>
<br>
<tr>
<td align="right">Email-ID:</td>
<td align="left"><input type="text" name="txtname" size=40>
</tr>
<tr>
<td></td>
<td><input type="button" value="SUBMIT" onClick="check()"/></td>
</tr>
</table>
</form>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
36

36

WEB TECHNOLOGIES LAB


MANUAL

<!Program for Phone number validation(Phone number should contain 10 digits


only)(phnvalid.html)-->
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
37

37

WEB TECHNOLOGIES LAB


<html>
MANUAL
<head>
<title>PHONE NUMBER VALIDATION</title>
<script language="javascript">
function phno()
{
var ph=f.ph.value;
if(ph.length==10)
{
if(isNaN(ph))
alert("It is not a valid Phone number");
else
alert("It is a valid Phone number");
}
else
alert("Please enter a valid phone number");
}
</script>
</head>
<body>
<form name="f">
<table align="center">
<br><br><br><br>
<h2 align="center">PHONE NUMBER VALIDATION</h2>
<br>
<tr>
<td align="right">PHONE NO:</td>
<td align="left"><input type="text" maxlength="15" size="30"
name="ph"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="SUBMIT" onClick="phno()"/></td>
</tr>
</table>
</form>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
38

38

WEB TECHNOLOGIES LAB


MANUAL

WEEK-4:
AIM: Design a web page using CSS (Cascading Style Sheets) which includes the following:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
39

39

WEB TECHNOLOGIES LAB


MANUAL
In the style definition you define how each selector should work (font, color etc.).
1. Use different font, styles:

Then, in the body of your pages, you refer to these selectors to activate the styles.
<!Program for creating inline style sheets(inline.html)-->
<head>
<title>inline style sheet</title>
</head>
<body>
normal bold:<b>web technologies</b><br>
after applying inline style
<b style="color:red;font-size:22px;font-family:arial;text-decoration:underline">Web
technologies</b>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
40

40

WEB TECHNOLOGIES LAB


MANUAL

2. Set a background image for both the page and single elements on the page.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
41

41

WEB TECHNOLOGIES LAB


<!Program for creating the background
image(image.html)-->
MANUAL
<html>
<head>
<style type="text/css">
body
{
background-image:url("F:\APVDL KUMAR\WEEK 4\Water lilies.jpg");
background-repeat:no-repeat
}
</style>
</head>
<body>
<center>
<font color=fuchsia>
<h1>Water Lilies</h1>
</font>
</center>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
42

42

WEB TECHNOLOGIES LAB


MANUAL

3. Control the repetition of the image with the background-repeat property.


A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
43

43

WEB TECHNOLOGIES LAB


MANUAL
Tiles the image until the entire page is filled, just like an ordinary background image in
As background-repeat: repeat
plain HTML.
<!Program for image repetition(imarepeat.html)-->
<html>
<head>
<style type="text/css">
body
{
background-image:url("F:\APVDL KUMAR\WEEK 4\water lilies.jpg");
background-repeat:repeat
}
h1
{
color:fuchsia;
font-size:40px;
}
</style>
</head>
<body>
<center>
<h1>Water Lilies</h1>
</center>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
44

44

WEB TECHNOLOGIES LAB


MANUAL

4. Define styles for links as

A:link

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
45

45

WEB TECHNOLOGIES LAB


A:visited MANUAL
A:active
A:hover
<!Defining styles using CSS(external.html)-->
<html>
<head>
<title>external style sheet</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body bgcolor="black">
<font color=white >normal bold : <b>Web technologies</b><br>
after applied embedded style :
<b class="headline">Web Technologies</b><br>
<b>
<a href="login.html" class="xlink">CROSS LINK</a>
<br>
<a href="login.html" class="hlink">HELP LINK</a><br><br>
<a href="login.html">another LINK</a>
</b>
</font>
</body>
</html>
Styles.css:
b.headline {color:green; font-size:22px; font-family:arial; text-decoration:underline}
.xlink {cursor:crosshair;color:cyan}
.hlink{cursor:help;color:purple}
A:link {text-decoration:none;color:green} /* unvisited link */
A:visited {text-decoration: none;color:yellow} /* visited link */
A:active {text-decoration: none;color:blue} /* selected link */
A:hover {text-decoration: underline; color: red} /* mouse over link */
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
46

46

WEB TECHNOLOGIES LAB


MANUAL

5. Work with layers:


<!Creating layers using CSS(layers.html)
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
47

47

WEB TECHNOLOGIES LAB


MANUAL

<html>
<head>
<title>Layers Demo</title>
</head>
<body>
LAYER 1 ON TOP

<div style="position:relative;font-size:50px;z-index:2;">LAYER1</div>
<div style="position:relative;top:-50;left:5;color:red;font-size:80px;zindex:1;">LAYER2</div>
LAYER 2 ON TOP
<div style="position:relative;font-size:50px;z-index:3;">LAYER1</div>
<div style="position:relative;top:-50;left:5;color:red;font-size:80px;zindex:4;">LAYER2</div>
</body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
48

48

WEB TECHNOLOGIES LAB


MANUAL

6. Add a customized cursor:


<!Program for representing the various cursors(cursors.html)
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
49
49

WEB TECHNOLOGIES LAB


<html>
MANUAL
<head><title>Cursor demo</title>
<style type="text/css">
.link1{cursor:default}
.link2{cursor:crosshair}
.link3{cursor:hand}
.link4{cursor:move}
.link5{cursor:text}
.link6{cursor:wait}
.link7{cursor:help}
.link8{cursor:n-resize}
.link9{cursor:s-resize}
.link10{cursor:e-resize}
.link11{cursor:w-resize}
.link12{cursor:progress}
.link13{cursor:not-allowed}
.link14{cursor:no-drop}
.link15{cursor:all-scroll}
</style></head>
<body>
<b>
<a href="login.html" class="link1">default cursor</a>
<br>
<a href="login.html" class="link2">crosshair cursor</a>
<br>
<a href="login.html" class="link3">hand cursor</a>
<br>
<a href="login.html" class="link4">move cursor</a>
<br>
<a href="login.html" class="link5">text cursor</a>
<br>
<a href="login.html" class="link6">wait cursor</a>
<br>
<a href="login.html" class="link7">help cursor</a>
<br>
<a href="login.html" class="link8">n-resize cursor</a>
<br>
<a href="login.html" class="link9">s-resize cursor</a>
<br>
<a href="login.html" class="link10">e-resize cursor</a>
<br>
<a href="login.html" class="link11">w-resize cursor</a>
<br>
<a href="login.html" class="link12">progress cursor</a>
<br>
<a href="login.html" class="link13">not allowed cursor</a>
<br>
<a href="login.html" class="link14">no-drop cursor</a>
<br>
<a href="login.html" class="link15">all-scroll cursor</a>
<br>
</b></body>
</html>

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
50

50

WEB TECHNOLOGIES LAB


MANUAL

WEEK-5:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
51

51

WEB TECHNOLOGIES LAB


AIM: Write an XML file which will displayMANUAL
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. Display 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. Use XML schemas
XSL and CSS for the above purpose.
<!Program for creating DTD for the XML file (dtd.xml)-->
<?xml version="1.0" ?>
<?xml:stylesheet type="text/xsl" href="Style.xsl"?>
<!DOCTYPE BOOKS[
<!ELEMENT BOOKS (INFORMATION)>
<!ELEMENT INFORMATION (Book)>
<!ELEMENT Book (book_name,Author_name,ISBN_number,publisher,Edition,Price)>
<!ELEMENT book_name (#PCDATA)>
<!ELEMENT Author_name (#PCDATA)>
<!ELEMENT ISBN_number (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT Edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<BOOKS>
<INFORMATION>
<Book>
<book_name>XML BIBLE</book_name>
<Author_name>RAJA</Author_name>
<ISBN_number>11530-115</ISBN_number>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
52

52

WEB TECHNOLOGIES LAB


<publisher>Pearson</publisher>
MANUAL
<Edition>I-Edition</Edition>
<Price>750</Price>
</Book>
<Book>
<book_name>HTML</book_name>
<Author_name>DIETL</Author_name>
<ISBN_number>11528-115</ISBN_number>
<publisher>wiley</publisher>
<Edition>III-Edition</Edition>
<Price>470</Price>
</Book>
<Book>
<book_name>JAVASCRIPT</book_name>
<Author_name>RANI</Author_name>
<ISBN_number>11525-115</ISBN_number>
<publisher>Techical</publisher>
<Edition>IV-Edition</Edition>
<Price>270</Price>
</Book>
<Book>
<book_name>WEB TECHNOLOGIES</book_name>
<Author_name>PUNTAMBEKAR</Author_name>
<ISBN_number>11530-115</ISBN_number>
<publisher>Technical</publisher>
<Edition>I-Edition</Edition>
<Price>340</Price>
</Book>
</INFORMATION>
</BOOKS>
<!Creating style sheets for the XML page(Style.xsl)
<?xml version="1.0" ?>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
53

53

WEB TECHNOLOGIES LAB


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
MANUAL
<xsl:template match="/">
<html>
<body>
<h2 align="center">My BOOK Collection</h2>
<table border="1" align="center">
<tr bgcolor="GRAY">
<th><font color="white"> BOOK_NAME</font></th>
<th><font color="white"> Author</font></th>
<th><font color="white"> ISBN</font></th>
<th><font color="white"> Publisher</font></th>
<th><font color="white"> Edition</font></th>
<th><font color="white"> Price</font></th>
</tr>
<xsl:for-each select="BOOKS/INFORMATION/Book">
<tr>
<td><xsl:value-of select="book_name"/></td>
<td bgcolor="black"><b><font color="white">
<xsl:value-of select="Author_name"/></font></b></td>
<td><xsl:value-of select="ISBN_number"/></td>
<td><xsl:value-of select="publisher"/></td>
<td><xsl:value-of select="Edition"/></td>
<td><xsl:value-of select="Price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
54

54

WEB TECHNOLOGIES LAB


MANUAL

WEEK-6:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
55

55

WEB TECHNOLOGIES LAB


MANUAL
AIM: Create a simple visual bean with a area filled with a color.
VISUAL BEANS:

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 .
Procedure:
Developing a Simple Bean Using the BDK:
This section presents an example that shows how to develop a simple Bean and
connect it to other components via the BDK.
Our new component is called the Colors Bean. It appears as either a circle or square that is
filled with a color. A color is chosen at random when the Bean begins execution. A public
method can be invoked to change it. Each time the mouse is clicked on the Bean, another
random color is chosen. There is one boolean read/write property that determines the shape.
The BDK is used to lay out an application with one instance of the Colors Bean
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.
Create a Directory for the New Bean:
You need to make a directory for the Bean. To follow along with this example, create
D:\kumar\week6\. Then change to that directory.

OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
56

56

WEB TECHNOLOGIES LAB


MANUAL

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
57

57

WEB TECHNOLOGIES LAB


Create the Source File for the New Bean:MANUAL
The source code for the Colors component is shown in the following listing. It is
located in the file Colors.java.
The import statement at the beginning of the program is used to import the packages of io,
awt, beans. These are packages used to run the io applications, event handlers and beans .The
color of the component is determined by the private Color variable color, and its shape is
determined by the private boolean variable square.
The constructor defines an anonymous inner class that extends MouseAdapter and
overrides its mousePressed( ) method. The change( ) method is invoked in response to
mouse presses. The component is initialized to a square shape of 200 by 100 pixels.
The change( ) method is invoked to select a random color and repaint the component.
The getsquare( ) and setSquare( ) methods provide access to the one property of this Bean.
The change( ) method calls randomColor( ) to choose a color and then calls repaint( ) to make
the change visible. Notice that the paint( ) method uses the square and color variables to
determine how to present the Bean.
// A simple Color Bean (Colors.java)
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
public class Colors extends Canvas
{
transient private Color color;
private boolean square;
public Colors()
{
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
change();
}
});
square = false;
setSize(200, 100);
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
58

58

change();

WEB TECHNOLOGIES LAB


MANUAL

}
public boolean getsquare() {
return square;
}
public void setSquare(boolean flag) {
this.square = 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);
/*g.setColor(getForeground());*/
if(square) {
g.fillRect(40, 40, 80, 80);
}
else {
g.fillOval(30, 30, 80, 80);
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
59

59

WEB TECHNOLOGIES LAB


MANUAL

}
}
}

Compile the source code to create a class file. Type the following:
D:\kumar\week6>javac Colors.java on the command prompt
Create a Manifest File:
You must now create a manifest file. First, switch to the D:\kumar\week6 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:
Name: Colors. class
Java-Bean: True
(Here one space must be required after Name: and Java-Bean: & after writing True
carriage return(press enter))
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 is in the package D:\kumar\week6
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:\beans\jars. These files are generated with the jar utility. Enter the following:
D:\kumar\week6>jar cfm Colors.jar colors.mft *.class
This command creates the file Colors.jar and places it in the directory D:\beans\jars.
(You may wish to put this in a batch file for future use.)
Start the BDK:
Change to the directory D:\beans\beanbox and type run. This causes the BDK to start.
You should see four windows, titled ToolBox, BeanBox, Properties and Method Tracer. The
ToolBox window should include an entry labeled Colors for your new Bean.
Create an Instance of the Colors Bean
After you complete the preceding steps, create an instance of the Colors Bean in the
BeanBox window by dropping the Color bean into BeanBox. Test your new component by
pressing the mouse anywhere within circle or square shape. Its color immediately changes.
Use the Properties window to change the square property from false to true. Its shape
immediately changes.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
60

60

WEB TECHNOLOGIES LAB


MANUAL
AIM: 1) Install TOMCAT web server and APACHE.
WEEK-7:

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. Access the
pages by using the urls : http://localhost:4040/rama/books.html (for
tomcat)http://localhost:8080/books.html (for Apache)
1) Tomcat Server Installation Procedure:
Visit the Apache Website http://tomcat.apache.org to get the latest information. On
the home page, click the link Tomcat 5.x under the heading Download. Scroll down the page
until you find the heading 5.5.23, under which you will find sub heading Binary
Distributions.(for ex zip,exe,tar). But the choice of download may depend up on your
operating system.If you are using windows o.s download either the .zip file(apache-tomcat5.5.23.zip) or the .exe file(apache-tomcat-5.5.23.exe).
If you are using unix based o.s download the .tar.gz file(apache-tomcat5.5.23.tar.gz) Installing Under Windows O.S :If you have downloaded the .zip version of Tomcat, simply extract the content using a file
extractor tool (such as winzip or winrar) to the c:\drive.
(After the extraction process is completed, you will find a directory named apache-tomcat5.5.23 and a no.of subdirectories under it including a couple of files such as RUNNING.TXT,
NOTICE.FILE, RELEASE-NOTES.FILE and LICENSE.FILE .)
Note 1 : you may also use the Jar command that comes with JDK, to extract the content. The
command is Jar -xvf apache-tomcat-5.5.23.zip
Note 2 : if you wish , you can rename the directory apache-tomcat-5.5.23 with a convenient
and shorter name as tomcat 5.5
Note 3 : directory containing tomcat(c:\apache-tomcat-5.5.23) is called
CATALINA_HOME, and if you want tomcat to work correctly set this variable. if you have
download the .exe version, installation is very easy. Execute the apache-tomcat.5.5.23.exe
either by selecting open or double-click it.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
61

61

WEB TECHNOLOGIES LAB


The following window would appear on your
desktop.
MANUAL

During the installation you may have to make several choices such as Choosing the features
of tomcat :- you have the options to select Normal, full , minimum or custom, select one
among them.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
62

62

WEB TECHNOLOGIES LAB


Choosing the installation location : defaultMANUAL
location would be c:\program files\apache
software foundation\tomcat 5.5 (CATALINA_HOME) of course you may also choose the
location you want.

choosing the port number, username , and password : Default port number is
8080, of course you may also choose the port number of your choice, provide user name and
password.

Choosing the JVM : Default JVM would be automatically selected, if you have multiple
JVMs installed on your system, provide a suitable path here.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
63

63

WEB TECHNOLOGIES LAB


MANUAL

Click on Install button, then you will see the following windows screen :-

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
64

64

WEB TECHNOLOGIES LAB


MANUAL

Finally you will see the following window if the installation is successfully completed.

Deployment Procedure in Tomcat Server:


Project
Name

WEB-INF

classes

[. html] files

web.xml

[. Java] and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
65

65

[.class] files

WEB TECHNOLOGIES LAB


MANUAL
1.1.1.1 Introduction to Servlets

Servlets provide a Java(TM)-based solution used to address the problems currently


associated with doing server-side programming, including inextensible scripting solutions,
platform-specific APIs, and incomplete interfaces.
Servlets are objects that conform to a specific interface that can be plugged into a
Java-based server. Servlets are to the server-side what applets are to the client-side -- object
byte codes that can be dynamically loaded off the net. They differ from applets in that they
are faceless objects (without graphics or a GUI component). They serve as platformindependent, dynamically loadable, plug gable helper byte code objects on the server side
that can be used to dynamically extend server-side functionality.
What is a Servlet?
Servlets are modules that extend request/response-oriented servers, such as Javaenabled web servers. For example, a servlet might be responsible for taking data in an HTML
order-entry form and applying the business logic used to update a companys order database.

Servlets are to servers what applets are to browsers. Unlike applets, however, Servlets
have no graphical user interface. Servlets can be embedded in many different servers because
the servlet API, which you use to write Servlets, assumes nothing about the server's
environment or protocol. Servlets have become most widely used within HTTP servers; many
web servers support the Servlet API.
1.1.1.1 The ServletResponse Interface:
The ServletResponse interface gives the servlet methods for replying to the client. It
allows the servlet to set the content length and MIME type of the reply. Provides an output
stream, ServletOutputStream, and a Writer through which the servlet can send the reply data.
Interfaces that extend the ServletResponse interface give the servlet more protocolspecific capabilities. For example, the HttpServletResponse interface contains methods that
allow the servlet to manipulate HTTP-specific header information.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
66
66

WEB TECHNOLOGIES LAB

1.1.2 Additional Capabilities MANUAL


of HTTP Servlets:

The classes and interfaces described above make up a basic Servlet. HTTP Servlets
have some additional objects that provide session-tracking capabilities. The servlet writer can
use these APIs to maintain state between the servlet and the client that persists across
multiple connections during some time period. HTTP Servlets also have objects that provide
cookies. The servlet writer uses the cookie API to save data with the client and to retrieve this
data.
The classes mentioned in the Architecture of the Servlet Package section are shown in
the example in bold:

SimpleServlet extends the HttpServlet class, which implements the Servlet interface.

SimpleServlet overrides the doGet method in the HttpServlet class. The doGet method
is called when a client makes a GET request (the default HTTP request method) and
results in the simple HTML page being returned to the client.

Within the doGet method an HttpServletRequest object represents the users request.

An HttpServletResponse object represents the response to the user.

Because text data is returned to the client, the reply is sent using the Writer object
obtained from the HttpServletResponse object.

1.1.2.1.1 Servlet Lifecycle:

Each servlet has the same life cycle

A server loads and initializes the servlet

The servlet handles zero or more client requests

The server removes the servlet

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
67

67

WEB TECHNOLOGIES LAB


MANUAL

2) AIM: 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:4040/rama/books.html (for
tomcat)http://localhost:8080/books.html (for Apache)
Procedure:
Step1: The web pages developed in week-1 and week-2 can be grouped together and give the
folder name as week7 and this folder pasted on the following link
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
Step2: After successful installation of Tomcat in our system, go to START->Programs
->Apache Tomcat 6.0->Configure Tomcat as shown shown in below:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
68

68

WEB TECHNOLOGIES LAB


MANUAL
Then click on Configure Tomcat option here appears the following window, and click on
Start button in order to Start the Tomcat server.

Fig: After clicking Configure Tomcat

Fig: After clicking Start to run Tomcat

Step3: Open some web browser(internet explorer) and type the URL http://localhost:8080
in address bar (or) simply go to Start->Programs->Apache Tomcat 6.0-> Welcome option
then you will get the following window:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
69

69

WEB TECHNOLOGIES LAB


Here in the above window click the TomcatMANUAL
Manager option on the left side then you will get
the below window to provide the authentication it means here you will give the username as
admin and then press ok

After clicking the ok button in the above window then you will get the following window

Here you can find the week7 folder i.e whatever you done in the step1.Then click the week7
in the above webpage you will get the following output, here you can see our week1 and
week2 web pages can be run under week7 folder in the Tomcat server i.e.
http://localhost:8080/week7 as shown in below figure.Here http is a Hyper Text Transfer
Protocol which is used to transfer the data from one web page into another web page and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
70

70

WEB TECHNOLOGIES LAB


localhost is the DNS(Domain Naming Service
or Server) and 8080 is the default port number
MANUAL
of our Tomcat Web Server and week7 is our application.

Step4: For example in the Tomcat installation process if you will give the port number as
4040 then you must access the week7 application through the following link
http://localhost:4040/week7 .
Step5: After successful execution of our week7 application you should stop the Tomcat
Server by clicking the stop button , it is shown in the below windows.

Fig: When Tomcat Sever started

Fig: After clicking stop button to stop the


Tomcat server.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
71

71

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:
Here in the below login page type user1 as username and pwd1 as password:

Click submit button, then another window will appear in which the CookieDemo servlet is
invoked. Hence you will get the following window

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
72

72

WEB TECHNOLOGIES LAB


MANUAL

WEEK-8:
AIM: 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 ids 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.
Procedure:
This assignment can be performed in two ways- in the first approach we will make use of
cookies to store username and password. In the second way, we will make use of init
parameters to store the user names and password in webinf.xml file. let us see the first way of
authenticating user.
a)Use of cookies:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
73

73

WEB TECHNOLOGIES LAB


Step 1: create a login form as follows(Login.html)
MANUAL
<html>
<head>
<title>Input Form</title>
</head>
<body>
<center>
<form name="form1" method="post" action="http://localhost:8080/week8/cookie">
<h3>Login Page</h3>
<table>
<tr>
<td><b>User Name:</b></td>
<td><input type="text" name="User_name" size="25" ></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="pwd" size="25"></td>
</tr>
</table>

OUTPUT:
Now in the address bar type getCookie then you will get the following window.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
74

74

WEB TECHNOLOGIES LAB


Again go to login form and give the user name
as user1 and password as pwd2.You will get
MANUAL
the following output:

<input type=submit value="submit">


</form>
</center>
</body>
</html>
Step 2: Create a java program for adding cookie for user name and password.
CookieDemo.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CookieDemo extends HttpServlet
{
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
75
75

WEB TECHNOLOGIES LAB


res.setContentType("text/html");
MANUAL
Cookie My_cookie=new Cookie("null","null");
Enumeration keys;
String key,value;
PrintWriter out=res.getWriter();
keys=req.getParameterNames();
while(keys.hasMoreElements())
{
key=(String)keys.nextElement();
value=req.getParameter(key);
My_cookie=new Cookie(value,key);
res.addCookie(My_cookie);}
out.println("\n the Cookie is added");
out.close();
}
}
Store the above program in the tomcat directory at webapps directory. To generate a class file
in that folder by compiling above program.
My Tomcat directory is
C:\Program Files\Apache Software Foundation\Tomcat 6.0
Hence I store the above program at the path
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEBINF\classes
Now using command prompt I have given following command to generate class file
javac CookieDemo.java
If there are no errors in your code that is at the pathC:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEBINF\classes
The class file named CookieDemo.class gets generated.
Step 3: Now create another java program for reading the Cookies.
getCookieServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class getCookieServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
Cookie[] my_cookies=req.getCookies();
String[] name=new String[10];
String[] value=new String[10];
int i;
res.setContentType("text/html");
PrintWriter out=res.getWriter();
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
76
76

WEB TECHNOLOGIES LAB


out.println("<b>");
MANUAL
int n=my_cookies.length;
for(i=0;i<n;i++)
{
name[i]=my_cookies[i].getName();
value[i]=my_cookies[i].getValue();
}
for(i=0;i<n;i=i+1)
{
try
{
out.println("<br>");
if(name[i].equals("pwd1"))
{
if(name[i+1].equals("user1"))
{
out.println("Welcome"+name[i+1]);
}
else
{
out.println("You are not authentic user!!!");
}
}
else if(name[i].equals("pwd2"))
{
if(name[i+1].equals("user2"))
{
out.println("Welcome"+name[i+1]);
}
else
{
out.println("You are not authentic user!!!");
}
}
else if(name[i].equals("pwd3"))
{
if(name[i+1].equals("user3"))
{
out.println("Welcome"+name[i+1]);
}
else
{
out.println("You are not authentic user!!!");
}
}
else if(name[i].equals("pwd4"))
{
if(name[i+1].equals("user4"))
{
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
77

77

WEB TECHNOLOGIES LAB


out.println("Welcome"+name[i+1]);MANUAL

}
else
{
out.println("You are not authentic user!!");
}
}
}
catch(Exception e)
{
out.println("Invalid username/password");
}
}
out.close();
}
}

To get the class file for above program we use this command
javac getCookieServlet.java
This class file must be at the path
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEBINF\classes
Step 4:
In the WEB-INF directory
(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEB-INF)
there is web.xml file. Open it using notepad and type as follows.
<web-app>
<servlet>
<servlet-name>CookieDemo1</servlet-name>
<servlet-class>CookieDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CookieDemo1</servlet-name>
<url-pattern>/cookie</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>getCookieServlet1</servlet-name>
<servlet-class>getCookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getCookieServlet1</servlet-name>
<url-pattern>/getCookie</url-pattern>
</servlet-mapping>
</web-app>
Save this file and exit.
Step 5:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
78

78

WEB TECHNOLOGIES LAB


Now open some web browser and invoke your
login page which is created in the first step.
MANUAL
You will get above output.

OUTPUT:
Here in the below login page type username as user1 and password as pwd1:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
79

79

WEB TECHNOLOGIES LAB


On clicking the submit button the getuserServlet
invoked and following output will be
MANUAL
obtained.

b)Use of init-parameters:
Now if we want to validate a user using the getInitParameters() method then follow the
following stepsstep 1: create a login form as follows(Login.html)
<html>
<head>
<title>Input Form</title>
</head>
<body>
<center>
<form name="form 1" method=get action="http://localhost:8080/week8b/gangaraju">
<h3>Login Page</h3>
<table>
<tr>
<td><b>UserName:</b></td>
<td><input type="text" name="User_name" size="25" value=""></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="pwd" size="25" value=""></td>
</tr>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
80

80

WEB TECHNOLOGIES LAB


</table>
MANUAL
<input type=submit value="submit">
</form>
</center></body>
</html>
Step 2: In the WEB-INF directory
(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8b\WEBINF) there is web.xml file. Open it using notepad and type as follows
<web-app>
<servlet>
<servlet-name>getuserServlet1</servlet-name>
<servlet-class>getuserServlet</servlet-class>
<init-param>
<param-name>UserName</param-name>
<param-value>user1</param-value>
</init-param>
<init-param>
<param-name>Password</param-name>
<param-value>pwd1</param-value>
</init-param>
</servlet>
<servlet-mapping>

OUTPUT:
Again go back to login page and give the user name as user1 and password as pwd3 you will
get the following output:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
81

81

WEB TECHNOLOGIES LAB


MANUAL

<servlet-name>getuserServlet1</servlet-name>
<url-pattern>/gangaraju</url-pattern>
</servlet-mapping>
</web-app>
Save this web.xml file and close it.
Step 3: Now write a java servlet program as follows:
getuserServlet.java
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
82

82

WEB TECHNOLOGIES LAB


import java.io.*;
MANUAL
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class getuserServlet extends HttpServlet
{
private String UserName,Password;
public void init()
{
ServletConfig config=getServletConfig();
UserName=config.getInitParameter("UserName");
Password=config.getInitParameter("Password");
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
Enumeration keys;
String key;
String[] value=new String[4];
int i=0;
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<b>");
keys=req.getParameterNames();
while(keys.hasMoreElements())
{
key=(String)keys.nextElement();
value[i]=req.getParameter(key);
i++;
}
i=0;
if((UserName.equals(value[i+1]))&&(Password.equals(value[i])))
{
out.println("<h2>");
out.println("welcome"+UserName+"!!!");
}
else
{
out.println("<h2>");
out.println("you are not an authentic user");
}
out.close();
}
}
Now compile the above program using the following command
javac getuserServlet.java
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
83

83

WEB TECHNOLOGIES LAB


This class file must be at the path
MANUAL
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8b\WEBINF\classes
Step 4: Now open some web browser and invoke your login page which is created in the first
step. You will get the above output.

Java Server Pages


A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
84

84

WEB TECHNOLOGIES LAB


Java Server Pages technology
lets you put snippets of servlet code directly
MANUAL
into a text-based document. A JSP page is a text-based document that contains two types of
text: static template data, which can be expressed in any text-based format such as HTML,
WML, and XML, and JSP elements, which determine how the page constructs dynamic
content.
Java Server Page(JSP): An extensible Web technology that uses template data, custom
elements, scripting languages, and server-side Java objects to return dynamic content to a
client. Typically the template data is HTML or XML elements, and in many cases the client is
a Web browser.
According to JSP model1 we can develop the application as,

According to above model the presentation logic has to be implemented in JSP page
and the business logic has to be implemented as part of Java bean This model help us in
separating the presentation and business logic. For large-scale projects instead of using
model1 it is better to use model2 (MVC). Struts framework is based on model 2.
Java Server Pages (JSP) lets you separate the dynamic part of your pages from the
static HTML. You simply write the regular HTML in the normal manner, using whatever
Web-page-building tools you normally use. You then enclose the code for the dynamic parts
in special tags, most of which start with "<%" and end with "%>". For example, here is a
section of a JSP page that results in something like "Thanks for ordering Core Web
Programming
For URL of http://host/OrderConfirmation.jsp?title=Core+Web+Programming:
Thanks for ordering
<I><%= request.getParameter ("title") %></I>
You normally give your file a .jsp extension, and typically install it in any place you
could place a normal Web page. Although what you write often looks more like a regular
HTML file than a servlet, behind the scenes, the JSP page just gets converted to a normal
servlet, with the static HTML simply being printed to the output stream associated with the
servlet's service method. This is normally done the first time the page is requested, and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
85

85

WEB TECHNOLOGIES LAB


developers can simply request the page themselves
when first installing it if they want to be
MANUAL
sure that the first real user doesn't get a

momentary delay when the JSP page is translated to a servlet and the servlet is compiled and
loaded. Note also that many Web servers let you define aliases that so that a URL that appears
to reference an HTML file really points to a servlet or JSP page.
Aside from the regular HTML, there are three main types of JSP constructs that you
embed in a page: scripting elements, directives, and actions. Scripting elements let you
specify Java code that will become part of the resultant servlet, directives let you control the
overall structure of the servlet, and actions let you specify existing components that should be
used, and otherwise control the behavior of the JSP engine. To simplify the scripting
elements, you have access to a number of predefined variables such as request in the snippet
above.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
86

86

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:
MySQL command prompt:

OUTPUT: (Registration_Form.jsp)

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
87

87

WEB TECHNOLOGIES LAB


MANUAL

WEEK-9
AIM: Install a database(Mysql or Oracle).
Create a table which should contain at least the following fields: name, password, emailid,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.
Procedure:
Step 1: Start MYSQL server goto Start->Programs->MySQLServer5.0->MySQL Command
Line Client then you will get the MySQL command prompt as shown in the output.
Step 2: create a database named registration_DB using following command on the MYSQL
prompt

mysql>CREATE DATABASE registration_DB;

Then create a table under the database registration_DB as followsA.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
88

88

WEB TECHNOLOGIES LAB


mysql>USEMANUAL
registration_DB;
mysql>CREATE TABLE registration_table(id INT(4) NOT NULL
AUTO_INCREMENT, name VARCHAR(50) NOT NULL, email VARCHAR(50)
NOT NULL, phone VARCHAR(10) NOT NULL, PRIMARY KEY(id));
The created table fields can be seen using following command
mysql>DESC registration_table;
Step 3: Now go to your tomcat directory in the webapps folder. There, in the examples
directory store the following JSP page. In my case I have stored my following jsp page name
Registration_Form.jsp at the path
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\examples\jsp
The JSP code as follows
Registration_Form.jsp:
<%@ page language="java" import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%
Connection conn=null;

OUTPUT:
The extracted data from the table will be displayed as follow:

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
89

89

WEB TECHNOLOGIES LAB


MANUAL

The submitted details can be stored in the MySQL server to check our student data is stored
or not .Here in the below figure it is successful and our data(JSP application data) is stored on
our database(MySQL) using JDBC connectivity.

ResultSet rs=null;
Statement stmt=null;
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
90

90

WEB TECHNOLOGIES LAB


Class.forName("com.mysql.jdbc.Driver").newInstance();
MANUAL
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/registration_DB","root","b
vcits");
out.write("conneted to mysql!!!");
stmt=conn.createStatement();
if(request.getParameter("action") !=null)
{
String Studname=request.getParameter("Studname");
String Studemail=request.getParameter("Studemail");
String Studphone=request.getParameter("Studphone");
stmt.executeUpdate("insert into registration_table(name,email,phone)
values('"+Studname+"','"+Studemail+"','"+Studphone+"')");
rs=stmt.executeQuery("select * from registration_table");
%>
<html>
<body>
<center>
<h2>Students List</h2>
<table border="1">
<tr>
<th>No</th>
<th>User Name</th>
<th>E-Mail</th>
<th>Phone</th>
</tr>
<%
int num=1;
while(rs.next())
{
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("email")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
conn.close();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
91

91

WEB TECHNOLOGIES LAB


<head>
MANUAL
<title>Student Registration Demo</title>
<script language="JavaScript">
function validation(Form_obj)
{
if((Form_obj.Studname.value.length==0)||(Form_obj.Studpass.value.length==0)||
(Form_obj.Studemail.value.length==0)||(Form_obj.Studphone.value.length!=10))
{
alert("Please,fill up the information,invalid data");
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form action="Registration_Form.jsp" method="post"
name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<table border="1">
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Student Registration Form</h2></td>
</tr>
<tr>
<td>StudentName:</td>
<td><input name="Studname" type="text" size="50"></td>
</tr>
<tr>
<td>StudentPassword:</td>
<td><input name="Studpass" type="password" size="50"></td>
</tr>
<tr>
<td>E-Mail:</td>
<td><input name="Studemail" type="text" size="50"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input name="Studphone" type="text" size="15"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type=submit value="SUBMIT"></td>
</tr>
</table>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
92

92

</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>

WEB TECHNOLOGIES LAB


MANUAL

Step 3:Open some web browser and give the address of above JSP
page(http://localhost:8080/examples/jsp/Registration_Form.jsp) in the address bar then
the output can be obtained.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
93

93

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:
Here in the below registration page type student name as user2 and password as pwd2

Here user2 is matched with the password pwd2, so authentication success.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
94

94

WEB TECHNOLOGIES LAB


MANUAL

WEEK-10:
AIM: 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).
Procedure:
Here we have assumed that there are four valid users user1, user2, user3, and user4
having passwords pwd1, pwd2, pwd3, and pwd4 respectively.
On the login page we must provide proper username and password. For instance user1
the password must be pwd1 and so on.
Step 1: Start MYSQL server goto Start->Programs->MySQLServer5.0->MySQL Command
Line Client then you will get the MySQL command prompt as shown in the output.
Step 2: create a database named registration_DB using following command on the MYSQL
prompt

mysql>CREATE DATABASE registration_DB;

Then create a table under the database registration_DB as followsmysql>USE registration_DB;


mysql>CREATE TABLE registration_table1(id INT(4) NOT NULL
AUTO_INCREMENT, name VARCHAR(50) NOT NULL, password VARCHAR(50) NOT
NULL ,email VARCHAR(50)
NOT NULL, phone VARCHAR(10) NOT NULL, PRIMARY KEY(id));
The created table fields can be seen using following command
mysql>DESC registration_table1;
Step 3: Now go to your tomcat directory in the webapps folder. There, in the examples
directory store the following JSP page. In my case I have stored my following jsp page name
Registration_Form1.jsp at the path
Registration_Form1.jsp
<%@ page language="java"import="java.sql.*"%>
<%@ page import="java.io.*"%>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
95
95

<%
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;

WEB TECHNOLOGIES LAB


MANUAL

OUTPUT:
Here in the below registration page type student name as user2 and password as
webtechnologies

Here user2 password should be pwd2, so it displays You have entered invalid
username/password, try again!!!

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
96

96

WEB TECHNOLOGIES LAB


MANUAL

Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/registration_DB","root","b
vcits");
stmt=conn.createStatement();
if(request.getParameter("action") !=null)
{
String Studname=request.getParameter("Studname");
String Studpass=request.getParameter("Studpass");
String Studemail=request.getParameter("Studemail");
String Studphone=request.getParameter("Studphone");
if(Studname.equals("user1") && Studpass.equals("pwd1"))
{
out.write("Welcome"+Studname);
stmt.executeUpdate("insert into registration_table1
(name,password,email,phone)values('"+Studname+"','"+Studpass+"','"
+Studemail+"', '"+Studphone+"')");
}
else if(Studname.equals("user2") && Studpass.equals("pwd2"))
{
out.write("Welcome"+Studname);
stmt.executeUpdate("insert into registration_table1(name,password,email,phone)
values('"+Studname+"','"+Studpass+"','"+Studemail+"','"+Studphone+"')");
}
else if(Studname.equals("user3") && Studpass.equals("pwd3"))
{
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
97

97

WEB TECHNOLOGIES LAB


out.write("Welcome"+Studname);MANUAL
stmt.executeUpdate("insert into registration_table1(name,password,email,phone)
values('"+Studname+"','"+Studpass+"','"+Studemail+"','"+Studphone+"')");
}
else if(Studname.equals("user4") && Studpass.equals("pwd4"))
{
out.write("Welcome"+Studname);
stmt.executeUpdate("insert into registration_table1(name,password,email,phone)
values('"+Studname+"','"+Studpass+"','"+Studemail+"','"+Studphone+"')");
}
else
{
out.write("\n You have entered invalid username/password,try again!!!");
}
out.write("<br/><br/>");
out.write("\n Current Records are.");
rs=stmt.executeQuery("select * from registration_table1");
%>
<html>

OUTPUT:
Here is the MySQL server command prompt, in this you check the your entered username
and password must be saved to check the user authentication and it is saved in our database.

A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,


BVCITS, AMALAPURAM
98

98

WEB TECHNOLOGIES LAB


MANUAL

<body>
<center>
<h2>Student List</h2>
<table border="1">
<tr>
<th>No</th>
<th>User Name</th>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
99

99

WEB TECHNOLOGIES LAB


<th>E-Mail</th>
MANUAL
<th>Phone</th>
</tr>
<%
int num=1;
while(rs.next())
{
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("email")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
conn.close();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Student Registration Demo</title>
<script language="javascript">
function validation(Form_obj)
{
if((Form_obj.Studname.value.length==0)||(Form_obj.Studpass.value.length==0)||
if(Form_obj.Studemail.value.length==0)||(Form_obj.Studphone.value.length!=10))
{
alert("Please,fill up theinformation,invalid data");
return false;
}
return true;
}
</script>
</head>
<body bgcolor=white>
<center>
<form action="Registration_Form1.jsp" method="post"
name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<table border="3" >
<tr>
A.P.V.D.L.KUMAR, (M.Tech) ASST. 100
PROFESSOR, BVCITS, AMALAPURAM

100

WEB TECHNOLOGIES LAB


<td>
MANUAL
<table>
<tr>
<td colspan="2" align="center">
<h2>Student Registration Form</h2></td>
</tr>
<tr>
<th>Student Name:</th>
<td><input name="Studname" type="text" size="50"></td>
</tr>
<tr>
<th>Student Password:</th>
<td><input name="Studpass" type="password" size="50"></td>
</tr>
<tr>
<th>E-Mail:</th>
<td><input name="Studemail" type="text" size="50"></td>
</tr>
<th>Phone:</th>
<td><input name="Studphone" type="text" size="15"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type=submit value="SUBMIT"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>
Step 3:Open some web browser and give the address of above JSP
page(http://localhost:8080/examples/jsp/Registration_Form1.jsp) in the address bar then
the output can be obtained.

OUTPUT:

A.P.V.D.L.KUMAR, (M.Tech) ASST. 101


PROFESSOR, BVCITS, AMALAPURAM

101

WEB TECHNOLOGIES LAB


MANUAL

A.P.V.D.L.KUMAR, (M.Tech) ASST. 102


PROFESSOR, BVCITS, AMALAPURAM

102

WEB TECHNOLOGIES LAB


MANUAL
WEEK-11:
AIM: 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.
Procedure:
Step1: In the MYSQL create a database named Catalog_DB Using following Command
mysql>CREATE DATABASE Catalog_DB;
We have to create a table inside this database mysql> USE Catalog_DB;
Then let us create a table named Catalog_table using following command
mysql>CREATE TABLE Catalog_table(id INT(4) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,author VARCHAR(50) NOT NULL,publication
VARCHAR(50) NOT NULL,isbn VARCHAR(35) NOT NULL,edition VARCHAR(20)
NOT NULL,price VARCHAR(15) NOT NULL,quantity VARCHAR(5) NOT
NULL,PRIMARY KEY(id));
Step2: Now go to your tomcat directory in the webapps folder. There, in the examples
directory store the following JSP page. In my case I have stored my following jsp page name
Catalog.jsp at the path
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\examples\jsp
The JSP code as follows
Catalog.jsp:
<%@ page language="java" import="java.sql.*"%>
<%@ page import="java.io.*"%>
<% Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Catalog_DB","root","bvci
ts");
stmt= conn.createStatement();
if(request.getParameter("action")!=null)
{
String Bookname=request.getParameter("Bookname");
String Bookauthor=request.getParameter("Bookauthor");
String Bookpublisher=request.getParameter("Bookpublisher");

A.P.V.D.L.KUMAR, (M.Tech) ASST. 103


PROFESSOR, BVCITS, AMALAPURAM

103

WEB TECHNOLOGIES LAB


MANUAL
OUTPUT:

Here is the MySQL command prompt which shows about our books details are stored in the
database.

A.P.V.D.L.KUMAR, (M.Tech) ASST. 104


PROFESSOR, BVCITS, AMALAPURAM

104

WEB TECHNOLOGIES LAB


MANUAL

String Bookisbn=request.getParameter("Bookisbn");
String Bookedition=request.getParameter("Bookedition");
String Bookprice=request.getParameter("Bookprice");
String Bookquantity=request.getParameter("Bookquantity");
stmt.executeUpdate("insert into
Catalog_table(name,author,publication,isbn,edition,price,quantity)values('"+Bookname+"','"+
Bookauthor+"','"+Bookpublisher+"','"+Bookisbn+"','"+Bookedition+"','"+Bookprice+"','"+Bo
okquantity+"')");
rs=stmt.executeQuery("select * from Catalog_table");
%>
<html>
<body>
<center>
<h2>Catalog Page</h2>
<table border="1" cellspacing="0"cellpadding="0">
<tr>
<th>S.No</th>
<th>Book Name</th>
<th>Author</th>
<th>Publisher</th>
<th>ISBN</th>
<th>Edition</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
int num=1;
while(rs.next()){
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%= rs.getString("author")%></td>
<td><%= rs.getString("publication")%></td>
<td><%= rs.getString("isbn")%></td>
<td><%= rs.getString("edition")%></td>
<td><%= rs.getString("price")%></td>
<td><%= rs.getString("quantity")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
A.P.V.D.L.KUMAR, (M.Tech) ASST. 105
PROFESSOR, BVCITS, AMALAPURAM

105

WEB TECHNOLOGIES LAB


conn.close();
MANUAL
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Book Details</title>
<script language="JavaScript">
function validation(Form_obj)
{
if((Form_obj.Bookname.value.length==0)||(Form_obj.Bookauthor.value.length==0)||
(Form_obj.Bookpublisher.value.length==0)||(Form_obj.Bookisbn.value.length==0)||
(Form_obj.Bookedition.value.length==0)||(Form_obj.Bookprice.value.length==0)||
(Form_obj.Bookquantity.value.length==0))
{
alert("Please,fill up the remaining information!!");
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form action="Catalog.jsp" method="post" name="entry" onSubmit="return
validation(this)">
<input type="hidden" value="list" name="action">
<table border="3" >
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Book Details Entry</h2></td>
</tr>
<tr>
<td>Book Name:</td>
<td><input name="Bookname" type="text" size="50"></td>
</tr>
<tr>
<td>Author Name:</td>
<td><input name="Bookauthor" type="text" size="50"></td>
</tr>
<tr>
<td>Publication:</td>
<td><input name="Bookpublisher" type="text" size="50"></td>
A.P.V.D.L.KUMAR, (M.Tech) ASST. 106
PROFESSOR, BVCITS, AMALAPURAM

106

WEB TECHNOLOGIES LAB


</tr>
MANUAL
<tr>
<td>ISBN:</td>
<td><input name="Bookisbn" type="text" size="35"></td>
</tr>
<tr>
<td>Edition:</td>
<td><input name ="Bookedition" type="text" size="20"></td>
</tr>
<tr>
<td>Price:</td>
<td>$<input name="Bookprice" type="text" size="15"></td>
</tr>
<tr>
<td>Quantity:</td>
<td><input name="Bookquantity" type="text" size="5"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type=submit value="SUBMIT"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>
Step 3:Open some web browser and give the address of above JSP
page(http://localhost:8080/examples/jsp/Catalog.jsp) in the address bar then the output
can be obtained.

A.P.V.D.L.KUMAR, (M.Tech) ASST. 107


PROFESSOR, BVCITS, AMALAPURAM

107

You might also like