0% found this document useful (0 votes)
59 views124 pages

AjWt Lab

The document contains sample HTML code for various HTML tags like headings, links, paragraphs, tables, forms and frames. It also includes the expected output for each code sample. The codes cover important tags and their usage in creating web pages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views124 pages

AjWt Lab

The document contains sample HTML code for various HTML tags like headings, links, paragraphs, tables, forms and frames. It also includes the expected output for each code sample. The codes cover important tags and their usage in creating web pages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 124

Exercise-1

1. Write an HTML program for Heading Tags

Program:--

<html>

<head>

<title>headings</title>

</head>

<body bgcolor='skyblue'>

<h1 align="center">Headings in Html</h1>

<h1>Hi Welcome To Pvpsit In Vijayawada</h1>

<h2>Hyper Text MarkUp Language</h2>

<h3>Cascading Style Sheets</h3>

<h4>Java Database Connectivity/h4>

<h5>Open Database Connectivity</h5>

<h6>Document Type Definition</h6>

</body>

</html>

Output:- -

1
2a.Write an HTML program for Link Tags

Program:-- ( Main program)

<html>

<head>

<title>Link</title>

</head>

<h1 align="justify">LINK</h1>

<body link="green" vlink="red" alink="blue">

<a href="petrol.html" target="XYZ">click here for petrol details</a>

</body>

</html>

Petrol.html

<html>

<body>

<table align="center" bgcolor="lightblue" width="30%" height="40%" border="1"


cellpadding="10" cellspacing="5">

<caption>

<h1>petrolcar</h1>

</caption>

<th>carmodel</th>

<th>regno</th>

<th>owner</th>

<tr align="center">

<td>maruthi</td>

<td>1243</td>

<td>abc</td>

</tr>

<tr align="center">

<td>chevrolet</td>

2
<td>3564</td>

<td>ghjfgh</td>

</tr>

</table>

</html>

Output:

3
2b.Write an HTML program for Hyperlink Tags

Program:--(main prgm)

<html>

<head>

<title>anchortag</title>

</head>

<body bgcolor="cyan">

<h1>Hyperlinks program</h1>

<a href="2b.anc.html">click here go to anchor1 page</a>

</body>

</html>

Program:--(anchor prgm)

<html>

<head>

<title>anchor tag</title>

</head>

<body bgcolor="alice blue">

<h1>Hyperinks Anchor1 program</h1>

<a href="2b.main.html">click here to go to main page</a>

</body>

</html>

4
Output:- -

5
3a.Write an HTML program for Paragraph Tags

Program:--(Paragraph Tag)

<html>

<head>

<title>Paragraph</title>

</head>

<body bgcolor="pink">

<h1 align="center"><br><br>Paragraph Tag</h1><br><br><br>

<b><font size="5"><p align="center">HTML (Hypertext Markup Language) is the set of markup


symbols or codes inserted in a file intended for display on a World Wide Web browser
page.</p></b></font>

<b><font size="5"><p align="right">HTML (Hypertext Markup Language) is the set of markup


symbols or codes inserted in a file intended for display on a World Wide Web browser
page.</p></b></font>

<b><font size="5"><p align="justify">HTML (Hypertext Markup Language) is the set of markup


symbols or codes inserted in a file intended for display on a World Wide Web browser
page.</p></b></font>

</body>

</html>

Output:

6
3b.Write an HTML program for pre Tags.

Program:- (Pre tag)

<html>

<head>

<title>Pre tag</title>

</head>

<body>

<h1 align="center">Pre-Tag</h1>

<pre align="left">HTML (Hypertext Markup Language) is the set of markup symbols

or

codes inserted in a file intended for display on a World Wide Web browser page.

The markup tells the Web browser how to display a Web page's words and images for the
user.</pre>

</body>

</html>

Output:

7
4. Write an HTML program for Image Tags

Program:--

<html>

<head>

</head>

<body BGCOLOR="PINK">

<h1 align="center">Image Tag</h1>

<h1 align="left">Absolute Path</h1>

<center><img src="http://www.pageresource.com/wallpapers/wallpaper/flowers-butterflies-
pictures-images_1664656.jpg" height="30%"width="30%"></center>

<br>

<h1 align="left">Relative Path</h1>

<center><img src="teju.jpg" height="30%" width="30%"></center>

</body>

</html>

Output:--

8
5. Write an HTML program for Table Tags along with all attributes.

Program:--

<html>

<head>

<title>table example</title>

</head>

<body bgcolor="pink">

<center><h1 align="top">STUDENT DETAILS</h1></center>

<br>

<br>

<br>

<table align="center" bgcolor="lightblue" width="30%" height="40%" border="1"


cellpadding="10" cellspacing="5">

<caption ALIGN="BOTTOM">

</caption>

<th>ROLL-NO</th>

<th>NAME</th>

<th>MARKS</th>

<tr align="center">

<td>100</td>

<td>Tejaswi</td>

<td>95</td>

</tr>

<tr align="center">

<td>101</td>

<td>Teju</td>

<td>96</td>

</tr>

<tr align="center">

9
<td>102</td>

<td>Teja</td>

<td>90</td>

</tr>

</table>

</html>

Output:--

10
Exercise-2

6. Write an HTML program for Frames Tags

Program:--

<html>

<head>

<title>Frame</title>

</head>

<frameset rows="50%,*">

<frame src="flag.html">

<frameset cols="50%,*">

<frame src="flower.html" Name="ABC">

<frame src="nature.html" Bame="XYZ">

</frameset>

</html>

Output:--

11
7. Write an HTML program for Form Tags

Program:--

<html>

<head>

<title>Forms</title>

<center>

<h1>Forms creation</h1>

</head>

<body bgcolor='skyblue' >

<form action='ss.html' method='post'>

<fieldset>

Name: <input type='text' value='register'></br>

Password: <input type='password' value='register'></br>

Education:</br>

<input type='checkbox' name='EQgroup'/> Graduate</br>

<input type='checkbox' name='EQgroup'/> PG<br/>

<input type='checkbox' name='EQgroup'/> Research<br/>

Gender:</br>

<input type='radio' name='Agegroup'/> M<br/>

<input type='radio' name='Agegroup'/> F<br/>

Address:</br>

<TextArea rows=5 cols=60></TextArea>

<br/>

birthday:</br>

<input type='Date' name='Bday/'>

</br>

<input type='submit' value='Register'></br>

<input type='Reset' value='clear'></br>

</fieldset>

12
</form>

</center>

</body>

</html>

Output:--

13
8. Write an HTML program for TimeTable using Table Tags

Program:--

<html>

<head>

</head>

<body bgcolor="#FFE4E">

<h1 align="center">Time Table</h1>

<table border="1" align="center" cellpadding="10" bgcolor="#AFEEEE">

<caption>

<h1>III B.tech-2 sem-2sec</h1>

</caption>

<th>Hours</th>

<th>1</th>

<th>2</th>

<th>3</th>

<th>4</th>

<th> </th>

<th>5</th>

<th>6</th>

<th>7</th>

<th>8</th>

<tr>

<th>Day/Time</th>

<th>9:30-10:20</th>

<th>10:20-11:10</th>

<th>11:20-12:10</th>

<th>12:10-1:00</th>

<th>1:00-2:00</th>

<th>2:00-2:50</th>

14
<th>2:50-3:40</th>

<th>3:40-4:30</th>

<th>4:30-5:00</th>

</tr>

<tr align="center">

<td><b>Mon</b></td>

<td>SE</td>

<td>WT</td>

<td>CN(T)</td>

<td>DAA</td>

<td rowspan="6">

<font size="5">L</font><br>

<font size="5">U</font><br>

<font size="5">N</font><br>

<font size="5">C</font><br>

<font size="5">H</font></td>

<td colspan="3"><center>DWDM lab</center></td>

<td> </td>

</tr>

<tr align="center">

<td><b>Tue</b></td>

<td>CN</td>

<td>SS</td>

<td>SE</td>

<td>DAA(T)</td>

<td colspan="3"><center>WT lab</center></td>

<td> </td>

</tr>

<tr align="center">

<td><b>Wed</b></td>

<td>DAA</td>

15
<td>DWDM</td>

<td>WT</td>

<td>SEM</td>

<td> SE</td>

<td>CN </td>

<td>DWDM</td>

<td> </td>

</tr>

<tr align="center">

<td><b>Thur</b></td>

<td>CN</td>

<td colspan="3"><center>CN lab</center></td>

<td>WT(T)</td>

<td>DWDM</td>

<td>DAA</td>

<td> </td>

</tr>

<tr align="center">

<td><b>Fri</b></td>

<td>WT</td>

<td>DAA</td>

<td>SE(T)</td>

<td>DWDM</td>

<td colspan="3"><center>WT lab</center></td>

<td> </td>

</tr>

<tr align="center">

<td><b>Sat</b></td>

<td>DWDM</td>

<td>WT</td>

<td>SE</td>

16
<td>CN</td>

<td> </td>

<td> </td>

<td> </td>

<td> </td>

</tr>

</table>

<br>

<br>

<br>

<br>

<br>

<table border="1" align="center" cellpadding="10" bgcolor="#fef8f8">

<th>SUBJECT NAME</th>

<th>NAME OF THE FACULTY</th>

<tr align="center">

<td>WEBTECHNOLOGIES</td>

<td>KVENKATESH/RAJESH/KN DIVYA</td>

</tr>

<tr align="center">

<td>WEBTECHNOLOGIES LAB</td>

<td>K VENKATESH/S PHANI PRAVEEN/B N SWAMY/

A SUDHIR BABU(TUE)/V SIVA PARVATAHI(FRI)</td>

</tr>

<tr align="center">

<td>COMPUTER NETWORKS</td>

<td>B.SRINIVAS RAO/SVISHNUVARDHAN/

DLOKESHSAIKUMAR</td>

</tr>

<tr align="center">

<td>DATAWARE HOUSING &DATA

17
MINING</td>

<td>V SIVAPARVATHI/K VENKATESH/

K VENUGOPAL</td>

</tr>

<tr align="center">

<td>SOFTWARE ENGINEERING</td>

<td>D SWAPNA/PANILKUMAR/KVENUGOPAL</td>

</tr>

<tr align="center">

<td>DESIGN &ANALYSIS OF

ALGORITHMS</td>

<td>V SOWJANYS/CH CHANDRA MOHAN/BSRINIVASARAO</td>

</tr>

<tr align="center">

<td>COMPUTER NETWORKS LAB</td>

<td>B.SRINIVAS RAO/V SOWJANYA/G LALITHA

KUMARI/ P ANIL KUMAR</td>

</tr>

<tr align="center">

<td>DATA MINING LAB</td>

<td>V SIVA PARVATHI/A RAMANA LAKSHMI/

K VENKATESH/V RAJESH</td>

</tr>

<tr align="center">

<td>SOFT SKILLS</td>

<td>L SUDHEERA</td>

</tr>

<<tr align="center">

<td>SEMINAR</td>

<td>D LOKESH SAI KUMAR/K NAGA DIVYA</td>

</tr>

18
<table>

</body> </html>

Output:--

19
Output:--

20
Exercise-3

9. Write an HTML program for BookStore Details.(Library)

Program:--

<html>

<head>

<title>main webpage</title>

</head>

<frameset rows="10%,4%,45%">

<frame src="onlineheading.html">

<frame src="onlineheading2.html">

<frameset cols="15%,*">

<frame src="leftframe.html">

<frame src="rightframe.html" name="right">

</frameset>

</frameset>

</html>

Login:

<html>

<body text="blue" bgcolor="radium">

<h1 align="center">login</h1>

<table height="30%" width="30%" align="center">

<tr align="center">

<td align="right"><h3>username</td>

<td align="left"><form method="post"><input type="text" name="un" size="30">

</form></td>

</tr>

<tr align="center">

<td align="right"><h3>password</td>

<td align="left"><form method="post"><input type="password" name="pwd" size="25">

21
<form></td>

</tr>

<tr align="center">

<td align="right"><form method="post"><input type="submit" value="submit"></form>

</td>

<td><form method="post"><input type="reset" value="reset"></form>

</td>

</tr>

</table>

</body>

</html>

Output:--

22
Registration:--

<html>

<head>

<title>registration</title>

</head>

<body>

<h2 align="center">REGISTRATION PAGE</h2>

<marquee scrollamount="10" behavior="alternate" bgcolor="pink"><b>Please enter the details to


register and click submit</b></marquee>

<table border="1" cellpadding="5" cellspacing="5" height="60%" width="60%">

<tr>

<td>

<form method="post">

<b>Name<input type="text" name="fn" placeholder="firstname"></b>

<input type="text" name="ln" placeholder="lastname">

<br>

</td>

</tr>

<tr>

<td>

<table>

<tr>

<td>

<b>DOB</b>::DD<select>

<optgroup>

<option value="0">0</option><option value="1">1</option><option value="2">2</option><option


value="3">3</option><option value="4">4</option><option value="5">5</option><option
value="6">6</option><option value="7">7</option><option value="8">8</option><option
value="9">9</option><option value="10">10</option>

<option value="11">11</option><option value="12">12</option><option


value="13">13</option><option value="14">14</option><option value="15">15</option><option

23
value="16">16</option><option value="17">17</option><option value="18">18</option><option
value="19">19</option><option value="20">20</option><option value="21">21</option><option
value="22">22</option><option value="23">23</option><option value="24">24</option><option
value="25">25</option><option value="26">26</option><option value="27">27</option>

<option value="28">28</option><option value="29">29</option><option


value="30">30</option><option value="31">31</option>

</optgroup>

</td>

<td>

MM<select>

<optgroup>

<option value="January">January</option><option value="February">February</option><option


value="Mar">March</option><option value="Apr">April</option>

<option value="May">May</option><option value="Jun">June</option><option


value="Jul">July</option><option value="Aug">August</option>

<option value="Sep">September</option><option value="Oct">October</option><option


value="Nov">November</option><option value="Dec">December</option>

</optgroup>

</td>

<td>

DD<select>

<optgroup>

<option value="1994">1994</option><option value="1995">1995</option><option


value="1996">1996</option><option value="1997">1997</option><option
value="1998">1998</option><option value="1999">1999</option><option
value="2000">2000</option><option value="2001">2001</option><option
value="2002">2002</option>

<option value="2002">2002</option><option value="2003">2003</option><option


value="2004">2004</option><option value="2005">2005</option><option
value="2006">2006</option><option value="2007">2007</option><option
value="2008">2008</option><option value="2009">2009</option><option
value="2010">2010</option>

<option value="2011">2011</option><option value="2012">2012</option><option


value="2013">2013</option><option value="2014">2014</option><option
value="2015">2015</option>

</optgroup>

</td>

</table>

24
</td>

</tr>

<tr>

<td>

<form method="post">

<b>Phone no:<input type="text" name="ph"></b>

<br>

</td>

</tr>

<tr>

<td>

<table>

<tr>

<td><b>Address:</b></td>

<td><textarea rows="10" cols="40">

</textarea></td>

<br>

</td>

</tr>

<tr>

<td>

<form method="post">

<b>Locality:<input type="text" name="loc"></b>

<br>

</td>

</tr>

<tr>

<td>

<form method="post">

<b>Pincode:<input type="text" name="pin"></b>

<br>

25
</td>

</tr>

<tr>

<td>

<table>

<tr>

<td>

<form>

<b>Gender::</b>Male<input type="radio" name="gender" value="male">

Female<input type="radio" name="gender" value="female">

</form>

</td></tr>

</table>

</td></tr>

<tr>

<td>

<form method="post">

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

<form method="post">

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

</td>

</tr>

</table>

</table>

<table>

<tr><td>

<img src="13.gif"></td>

<td>

<a href="webpage.html"><font face="Bookman Old Style" size="4" color="BLACK"><h3


align="center">BACK TO HOME</a>

</td></tr>

26
</table>

</body>

</html>

Output:--

27
Catalogue:

<html>

<head>

<title>catalogue</title>

</head>

<body>

<table border="1" align="center">

<th bgcolor="violet"><h3><i>cover page</th>

<th bgcolor="violet"><h3><i>Author name</th>

<th bgcolor="violet"><h3><i>Publisher</th>

<th bgcolor="violet"><h3><i>Price</th>

<th bgcolor="violet"><h3><i>Active cart button</th>

<tr align="center" bgcolor="yellow">

<td>

<img src="i1.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Pankaj sharma</td>

<td><h3>Katson books</td>

<td><h3>500</td>

</tr>

<tr align="center" bgcolor="blue">

<td>

<img src="i2.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Kentech</td>

<td><h3>Dreamtech press</td>

<td><h3>2000</td>

</td>

</tr>

<tr align="center" bgcolor="fa816f">

<td>

28
<img src="i3.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>A.Punambedkar</td>

<td><h3>Technical publications</td>

<td><h3>1000</td>

</td></tr>

<tr align="center" bgcolor="cyan">

<td>

<img src="i4.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Ian.H.Witlen</td>

<td><h3>M.K Publications</td>

<td><h3>2100</td>

</tr>

<tr align="center" bgcolor="blue">

<td>

<img src="i5.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Gaurav Giridhar</td>

<td><h3>Katson books</td>

<td><h3>680</td>

</tr>

<tr align="center" bgcolor="magenta">

<td>

<img src="i6.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Abraham</td>

<td><h3>wisley publications</td>

<td><h3>800</td>

</tr>

<tr align="center" bgcolor="yellow">

<td>

<img src="i7.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>Pradeep K Sinha</td>

<td><h3>E.E.E</td>

29
<td><h3>2010</td>

</tr>

<tr align="center" bgcolor="blue">

<td>

<img src="i8.jpg" alt="not available" height="10%" width="18%"/>

<td><h3>P.K.Yadav</td>

<td><h3>Katson books</td>

<td><h3>500</td>

</tr></table>

<table>

<tr><td>

<img src="13.gif"></td>

<td>

<a href="webpage.html"><font face="Bookman Old Style" size="4" color="BLACK"><h3


align="center">BACK TO HOME</a>

</td>

</tr>

</table>

</body>

</html>

Output:--

30
Add to Cart:--

<html>

<head>

<title>active cart button</title>

</head>

<body bgcolor="59ff52">

<a href="cart.html"><b>Add to cart</a>

</body>

</html>

Cart.html:--

<html>

<head>

31
<title>active cart button</title>

</head>

<body bgcolor="59ff52">

<h1>ADD TO CART</h1>

<br>

<br>

<center><img src="addtocart.jpg" width="80" height="100"></center>

</body>

</html>

Output:--

32
CSE:----

<html>

<head>

<title>catalogue</title>

</head>

<body bgcolor="black" text="white">

<table border="1" align="center">

<th><h3><i>cover page</th>

33
<th><h3><i>Author name</th>

<th><h3><i>Publisher</th>

<th><h3><i>Price</th>

<th><h3><i>Add to cart button</th>

<tr align="center">

<td>

<img src="i1.jpg" alt="not available" height="10%" width="15%"/>

<td><h3>Pankaj sharma</td>

<td><h3>Katson books</td>

<td><h3>500</td>

</tr>

<tr align="center">

<td>

<img src="i2.jpg" alt="not available" height="10%" width="15%"/>

<td><h3>Kentech</td>

<td><h3>Dreamtech press</td>

<td><h3>2000</td>

</td></tr>

Output:--

34
Final Output of the Book Store:----

35
EXERCISE-4

1.Write a HTML Program using Inline Style sheets

36
Program:

<html>
<body>
<h1 style="color:blue;margin-left:30px;">welcome</h1>
<p>normal text</p>
</body>
</html>

Output:--

2.Write a HTML Program using Internal stylesheet

Program:

<html>
<head>
<style>
h1 {

37
color:black;
margin-left:10px;
}
</style>
</head>
<body>
<h1>Welcome</h1>
<p>Welcome</p>
</body>
</html>

Output:---

3.Write a HTML Program using external stylesheet

Program:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</link>
</head>
<body>
<h1>Welcome</h1>
<p>Normal text</p>
</body>

38
</html>

stylesheet1.css:

h1{
color:red;
margin-left:50px;
}

Output:---

4.Write a HTML Program using Styles

Program:

<html>
<head>
<link rel="stylesheet" type="text/css" href="1.css">
</link>
</head>
<body>
<div id="header">Header</div>
<div id="left_column">Left column</div>
<div id="content">Msg content</div>
<div id="footer">Footer</div>
</body>
</html>

1.css:

39
#header
{
background-color:red;
width:"100%";
height:"10%";
}

#left_column
{
background-color:green;
width:30%;
height:80%;
float:left;
}

#content
{
background-color:violet;
width:70%;
height:80%;
float:left;
}

#footer
{
background-color:skyblue;
width:"100%";
}

Output:--

40
EXERCISE-5

1.Write a HTML Program using internal javascript

41
Program:

<html>
<head>
</head>
<body bgcolor="skyblue">
<script type="text/javascript" language="javascript">
document.write("hai hello");
</script>
</body>
</html>

Output:---

2.Write a HTML Program using external javascript

Program:

<html>
<head>
</head>
<body bgcolor="skyblue">
<script type="text/javascript" language="javascript" src=”first.js”>
document.write("hai hello");
</script>

42
</body>
</html>

First.js:

document.write("hai hello");

Output:--

3.Functions in java script

a.)Alert

<html>
<body>
<script>
alert("Hai");
</script>
</body>
</html>

Output:--

43
b.)Prompt

<html>
<body>
<script>
var no1=prompt("Enter first number");
var no2=prompt("Enter 2nd number");
var sum=n01+n02;
document.write(sum);
</script>
</body>
</html>
Output:--

44
c.)ParseInt:

<html>
<body>
<script>
var no1=parseInt(prompt("Enter number"));
var no2=parseInt(prompt("Enter number"));
var sum=no1+no2;
document.write(sum);
</script>
</body>
</html>

Output:--

45
d.)Confirm:

<html>
<body>
<script>
var n=confirm("Are you sure you want to delete this file");
if(n)
document.write("The document is deleted");
else
document.write("Welcome");
</script>
</body>
</html>

Output:--

46
e.)Eval:

<html>
<body>
<script>
eval("x=25;y=20;document.write(x+y)");
document.write("<br>"+eval("20+4"));
</script>
</body>
</html>

Output:--

f.)isFinite:

<html>
<body>
<script>
document.write(isFinite(345));
document.write("<br>"+isFinite("Hai"));

47
</script>
</body>
</html>

Output:--

g.)isNan:

<html>
<body>
<script>
document.write(isNaN(345));
document.write("<br>"+isNaN("Hai"));
</script>
</body>
</html>

Output:--

48
h.)NumberFunction:

<html>
<body>
<script>
document.write(Number(Boolean(true)));
document.write("<br>");
document.write(Number(Boolean(false)));
</script>
</body>
</html>

Output:--

4.Event handling Functions

a.)Onclick:

<html>
<head>
<script type="text/javascript" language="javascipt">
function findper(total_marks)

49
{
if(total_marks<100)
document.write("percentage="+(total_marks/3)+"<br>");
}
</script>
</head>
<body bgcolor="silver">
<form>
<input type="text" id="total"><br><br>
<input type="button" id="percen" value="percen"
onclick="findper(total.value)"><br><br>
</form>
</body>
</html>

Output:--

b.)OnLoad:

<html>
<head>
<script type="text/javascript" language="javascipt">
function myfun()
{
alert("Welcome");
}
</script>
</head>
<body bgcolor="silver" onload="myfun()">
</body>
</html>

50
Output:--

c.)Onmouseover:

<html>
<head>
<script type="text/javascript" language="javascipt">
function mouseover()
{
alert("Welcome");
}
</script>
</head>
<body bgcolor="silver">
<h1 onmouseover="mouseover()">Hai</h1>
</body>
</html>

Output:--

51
d.)onreset:

<html>
<head>
<script type="text/javascript" language="javascipt">
function rese()

{
alert("Are you sure you want to reset data");
}
</script>
</head>
<body>
<form onreset="rese()">
<input type="text" value="Enter the name">
<br><br>
<input type="reset" value="reset">
</form>
</body>
</html>

Output:--

52
e.)onSubmit:

<html>
<head>
<script type="text/javascript" language="javascript">
function submi()
{
alert("Are you sure you want to submit the details");
}
</script>
</head>
<body>
<form onsubmit="submi()">
<input tpe="text" value="Enter the name">
<br><br>
<input type="submit" value="submit">
</form>
</body>
</html>

Output:--

53
f.)onmouseout:

<html>
<head>
<script type="text/javascript" language="javascipt">
function mouseout()
{
alert("Welcome");
}
</script>
</head>
<body>
<h1 onmouseout="mouseout()">Hai</h1>
</body>
</html>

Output:--

54
g.)onfocus:

<html>
<body>
Enter your name:
<input type="text" onfocus="myfunc(this)">
<p>when the input field gets focus a function is triggered which changes the bgcolor</p>
<script>
function myfunc(x)
{
x.style.background="yellow";
}
</script>
</body>
</html>

Output:--

55
h.)onblur:

<html>
<body>
Enter your name:
<input type="text" onfocus="myFunc(this)" onblur="myfunc(this)">
<p>when the input field gets focus a function is triggered which changes the bgcolor</p>
<script>
function myFunc(x)
{
x.style.background="yellow";
}
function myfunc(y)
{
y.style.background="red";
}
</script></body>
</html>

Output:--

56
5.Java objects

a.)Array objects:

<html>
<body>
<script>
var a=new Array(3);
var b=new Array("Hai","Welcome","To wt");
a[0]=1;
a[1]=2.5;
a[2]="Hai";
document.write("Array length is "+a.length+"<br>");
document.write("Array concat is "+a.concat()+"<br>");
document.write("Array reverse is "+a.reverse()+"<br>");
document.write("Array sort is "+a.sort()+"<br>");
document.write("Array join is "+a.join()+"<br>");
</script>
</body>
</html>

Output:--

57
b.)String object:

<html>
<head>
<body>
<script>
var st="Welcome to wt";
var str="Happy programing";
document.write(st.length+"<br>");
document.write(st.bold()+"<br>");
document.write("the character at 10th position is "+st.charAt(11)+"<br>");
document.write(st.concat(str)+"<br>");
document.write(st.substring(3,10)+"<br>");
document.write(st.toLowerCase()+"<br>");
document.write(st.toUpperCase()+"<br>");
if(st.match(/wt/))
{ document.write("The string contains wt <br>");
}if(str.search(/Happy/)!=-1)
{ document.write(str.replace(/Happy/,"Enjoy"));
}
</script></body></head>
</html>

Output:--

58
c.)Date objects:

<html>
<head>
<script>
var dt=new Date();
var year=dt.getFullYear();
var date=dt.getDate();
var day=dt.getDay();
var month=dt.getMonth();
var days=new Array("sunday","monday","tuesday","wednesday","thursday","friday","saturday");
var months=new
Array("january","february","march","april","may","june","july","august","september","october","nov
ember","december");
</script>
</head>
<script>
document.write("Today is "+days[day]+" "+date+" "+months[month]+" "+year);
document.write("<br><br>");
document.write(dt.toString());
</script>
</html>

Output:---

59
EXERCISE-6

DHTML program:

<html lang="en"><head>

<meta charset="utf-8">

<title>JavaScript Form Validation using a sample registration form</title>

<meta name="keywords" content="example, JavaScript Form Validation, Sample registration


form" />

<meta name="description" content="This document is an example of JavaScript Form Validation


using a sample registration form. " />

<link rel='stylesheet' href='validation.css' type='text/css' />

<script src="validation.js"></script>

</head>

<body onload="document.registration.userid.focus();">

<h1>Registration Form</h1>

<p>Use tab keys to move from one input field to the next.</p>

<form name='registration' onSubmit="return formValidation();">

<ul>

<li><label for="userid">User id:</label></li>

<li><input type="text" name="userid" size="12" /></li>

60
<li><label for="passid">Password:</label></li>

<li><input type="password" name="passid" size="12" /></li>

<li><label for="username">Name:</label></li>

<li><input type="text" name="username" size="50" /></li>

<li><input type="text" name="address" size="50" /></li>

<li><label for="country">Country:</label></li>

<li><select name="country">

<option selected="" value="Default">(Please select a country)</option>

<option value="AF">Australia</option>

<option value="AL">Canada</option>

<option value="DZ">India</option>

<option value="AS">Russia</option>

<option value="AD">USA</option>

</select></li>

<li><label for="zip">ZIP Code:</label></li>

<li><input type="text" name="zip" /></li>

<li><label for="email">Email:</label></li>

<li><input type="text" name="email" size="50" /></li>

<li><label id="gender">Sex:</label></li>

<li><input type="radio" name="sex" value="Male" /><span>Male</span></li>

<li><input type="radio" name="sex" value="Female" /><span>Female</span></li>

<li><label>Language:</label></li>

<li><input type="checkbox" name="en" value="en" checked /><span>English</span></li>

<li><input type="checkbox" name="nonen" value="noen" /><span>Non English</span></li>

<li><label for="desc">About:</label></li>

<li><input type="submit" name="submit" value="Submit" /></li>

</ul>

</form>

61
</body>

</html>

validation.js:

function formValidation()

var uid = document.registration.userid;

var passid = document.registration.passid;

var uname = document.registration.username;

var uadd = document.registration.address;

var ucountry = document.registration.country;

var uzip = document.registration.zip;

var uemail = document.registration.email;

var umsex = document.registration.msex;

var ufsex = document.registration.fsex; if(userid_validation(uid,5,12))

if(passid_validation(passid,7,12))

if(allLetter(uname))

if(countryselect(ucountry))

if(allnumeric(uzip))

if(ValidateEmail(uemail))

if(validsex(umsex,ufsex))

62
{

return false;

} function userid_validation(uid,mx,my)

var uid_len = uid.value.length;

if (uid_len == 0 || uid_len >= my || uid_len < mx)

alert("User Id should not be empty / length be between "+mx+" to "+my);

uid.focus();

return false;

return true;

function passid_validation(passid,mx,my)

var passid_len = passid.value.length;

if (passid_len == 0 ||passid_len >= my || passid_len < mx)

alert("Password should not be empty / length be between "+mx+" to "+my);

passid.focus();

63
return false;

return true;

function allLetter(uname)

var letters = /^[A-Za-z]+$/;

if(uname.value.match(letters))

return true;

else

alert('Username must have alphabet characters only');

uname.focus();

return false;

function alphanumeric(uadd)

var letters = /^[0-9a-zA-Z]+$/;

if(uadd.value.match(letters))

return true;

else

alert('User address must have alphanumeric characters only');

64
uadd.focus();

return false;

function countryselect(ucountry)

if(ucountry.value == "Default")

alert('Select your country from the list');

ucountry.focus();

return false;

else

return true;

function allnumeric(uzip)

var numbers = /^[0-9]+$/;

if(uzip.value.match(numbers))

return true;

else

alert('ZIP code must have numeric characters only');

uzip.focus();

65
return false;

function ValidateEmail(uemail)

var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if(uemail.value.match(mailformat))

return true;

else

alert("You have entered an invalid email address!");

uemail.focus();

return false;

} function validsex(umsex,ufsex)

x=0;

if(umsex.checked)

x++;

} if(ufsex.checked)

x++;

if(x==0)

66
{

alert('Select Male/Female');

umsex.focus();

return false;

else

alert('Form Succesfully Submitted');

window.location.reload()

return true;

validation.css:

h1 {

margin-left: 70px;

form li {

list-style: none;

margin-bottom: 5px;

form ul li label{

float: left;

clear: left;

width: 100px;

text-align: right;

margin-right: 10px;

67
font-family:Verdana, Arial, Helvetica, sans-serif;

font-size:14px;

form ul li input, select, span {

float: left;

margin-bottom: 10px;

form textarea {

float: left;

width: 350px;

height: 150px;

[type="submit"] {

clear: left;

margin: 20px 0 0 230px;

font-size:18px

p{

margin-left: 70px;

font-weight: bold;

68
Output:---

69
EXERCISE-7

1.Well formed XML

program:

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


<note>
    <to> Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>
Output:--

XML Checking Finished

2.External DTD:

Program:

<?xml version="1.0" standalone=”yes”?>


< !DOCTYPE note SYSTEM "note.dtd">
<note>
 < to>Tove</to>
  < from>Jani</from>
 < heading>Reminder</heading>
 < body>Don't forget me this weekend!</body>
< /note>

Note.DTD:

<!ELEMENT note (to,from,heading,body)>


< !ELEMENT to (#PCDATA)>
< !ELEMENT from (#PCDATA)>
< !ELEMENT heading (#PCDATA)>
< !ELEMENT body (#PCDATA)>

Output:--

XML Checking Finished

3.Internal DTD:

program:

<?xml version="1.0"?>
< !DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>

70
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
< note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
< /note>

Output:--

XML Checking Finished

4.DOM parser

Program:

import java.io.File;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import org.w3c.dom.Node;

import org.w3c.dom.Element;

public class DomParserDemo1 {

public static void main(String[] args){

try {

File inputFile = new File("input.xml");

DocumentBuilderFactory dbFactory

= DocumentBuilderFactory.newInstance();

DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

Document doc = dBuilder.parse(inputFile);

doc.getDocumentElement().normalize();

71
System.out.println("Root element :"

+ doc.getDocumentElement().getNodeName());

System.out.println("----------------------------");

NodeList nList = doc.getElementsByTagName("student");

for (int temp = 0; temp < nList.getLength(); temp++) {

Node nNode = nList.item(temp);

System.out.println("\nCurrent Element :"

+ nNode.getNodeName());

if (nNode.getNodeType() == Node.ELEMENT_NODE) {

Element eElement = (Element) nNode;

System.out.println("Student roll no : ""+eElement.getAttribute("rollno"));

System.out.println("First Name :"+eElement.getElementsByTagName("firstname")

.item(0)

.getTextContent());

} catch (Exception e) {

e.printStackTrace();

5.XSLT:

Program:

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

<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>

<catalog>

72
<cd>

<title>Empire Burlesque</title>

<artist>Bob Dylan</artist>

<country>USA</country>

<company>Columbia</company>

<price>10.90</price>

<year>1985</year>

</cd>

<cd>

<title>Hide your heart</title>

<artist>Bonnie Tyler</artist>

<country>UK</country>

<company>CBS Records</company>

<price>9.90</price>

<year>1988</year>

</cd>

<cd>

<title>Greatest Hits</title>

<artist>Dolly Parton</artist>

<country>USA</country>

<company>RCA</company>

<price>9.90</price>

<year>1982</year>

</cd>

</catalog>

Cdcatalog.xsl:

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

73
<!-- Edited by XMLSpy® -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<body>

<h2>My CD Collection</h2>

<table border="1">

<tr bgcolor="#9acd32">

<th style="text-align:left">Title</th>

<th style="text-align:left">Artist</th>

</tr>

<xsl:for-each select="catalog/cd">

<tr>

<td><xsl:value-of select="title"/></td>

<td><xsl:value-of select="artist"/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

74
EXERCISE-8

1.write a java program using type1 drivers

Program:

import java.sql.*;
class type1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
Connection
con=DriverManager.getConnection("jdbc:odbc:section2","system","admin");
System.out.println("connection established");
Statement st=con.createStatement();
System.out.println("statement created");
st.executeUpdate("create table oneee(no number,name varchar2(20),address
varchar2(20))");
System.out.println("table created");
st.executeUpdate("insert into oneee values(87,'aa','bb')");
st.executeUpdate("insert into oneee values(89,'cc','dd')");
System.out.println("one row inserted");
ResultSet rs=st.executeQuery("select * from oneee");
System.out.println("result set generated");
st.executeUpdate("update oneee set name='Akhil' where no=89");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));
}
st.executeUpdate("delete from oneee where no=89");
ResultSet rs=st.executeQuery("select * from oneee");
System.out.println("result set generated");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));
}
rs.close();
st.close();
con.close();
}
}

2.write a java program using type4 drivers

Program:

75
import java.sql.*;
class type4
{
public static void main(String args[])throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","admin");
Statement st=con.createStatement();
System.out.println("statement created");
st.executeUpdate("create table one(no number,name varchar2(20),address
varchar2(20))");
System.out.println("table created");
st.executeUpdate("insert into one values(87,'aa','bb')");
st.executeUpdate("insert into one values(89,'cc','dd')");
System.out.println("one row inserted");
ResultSet rs=st.executeQuery("select * from one");
System.out.println("result set generated");
st.executeUpdate("update oneee set name='Akhil' where no=89");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));
}
st.executeUpdate("delete from one where no=89");
ResultSet rs=st.executeQuery("select * from one");
System.out.println("result set generated");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));
}
rs.close();
st.close();
con.close();
}
}

3. write a java program using Prepared statement

Program:

import java.sql.*;
import java.io.*;
class type42
{
public static voidmain(string args[])throws exception
{
Connection con=null;
PreparedStatement=null;
Class.forName("oracle:jdbc.driver.oracledriver")

con=driverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",""system","admin");
String query="insert into student values(?,?,?)";
ps=con.PreparedStatement(query);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));

76
System.out.println("enter number of students");
int n=Integer.parseInt(dis.readLine());
for(i=1;i<=n;i++)
{
System.out.println(Ënter student number");
int no=Integer.parseInt(dis.readLine());
System.out.println(Ënter studnt name");
String name=dis.readLine();
ps.setInt(1,no);
ps.setString(2,name);
int res=ps.executeUpdate();
if(res==1)
System.out.println("Success");
else
System.out.println("Fail);
}
}
}

4. write a java program using Callable statement

Program:

Import java.sql.*;

Import java.util.*;

class callstmt

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

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","admin");

CallableStatement cst=con.prepareCall("{call first(?,?)}");

cst.registerOutParameter(2,Types.INTEGER);

cst.setInt(1,20);

cst.execute();

int res=cst.getInt(2);

System.out.println("Result is"+res);

cst.close();

con.close();

77
}

5. write a java program using Resultsetmetadata

Program:

import java.sql.*;
class columnnames
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
Connection
con=DriverManager.getConnection("jdbc:odbc:section2","system","admin");
System.out.println("connection established");
Statement st=con.createStatement();
System.out.println("statement created");
st.executeUpdate("create table abc(no number,name varchar2(20),address
varchar2(20))");
System.out.println("table created");
st.executeUpdate("insert into abc values(87,'aa','bb')");
st.executeUpdate("insert into abc values(89,'cc','dd')");
System.out.println("one row inserted");
ResultSet rs=st.executeQuery("select * from abc");
System.out.println("result set generated");
ResultSetMetaData rsmd=rs.getMetaData();
String name=rsmd.getColumnName(2);
System.out.println(name);
}
}

EXERCISE-9

78
1. Write an Servlet Application program using Servlet Interface.

 Directory Structure:

 First.java

import java.io.*;

import javax.servlet.*;

public class First implements Servlet

ServletConfig config=null;

public void init(ServletConfig config)

this.config=config;

System.out.println("Servlet is initialized");

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

79
res.setContentType("text/html");

PrintWriter out=res.getWriter();

out.print("<html><body>");

out.print("<b>Hello,Welcome to pvpsit</b>");

out.print("</body></html>");

public void destroy()

System.out.println("Servlet is destroyed");

public ServletConfig getServletConfig()

return config;

public String getServletInfo()

return "hai";

 Web.xml:--

<web-app>

<servlet>

<servlet-name>Teja</servlet-name>

<servlet-class>First</servlet-class>

</servlet>

<servlet-mapping>

80
<servlet-name>Teja</servlet-name>

<url-pattern>/Welcome</url-pattern>

</servlet-mapping>

</web-app>

 Execution:

 Javac –cp e:\path\servlet-api.jar First.java

 localhost:2000/proj1/Welcome

Output:--

81
2. Write an Servlet Application program using GenericServlet class

 Directory Structure:

82
 Second.java:--

import java.io.*;

import javax.servlet.*;

public class Second extends GenericServlet

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

res.setContentType("text/html");

PrintWriter out=res.getWriter();

out.print("<html><body>");

out.print("<b>Welcome to Pvpsit</b>");

out.print("</body></html>");

 Web.xml:--

<web-app>

83
<servlet>

<servlet-name>Teja</servlet-name>

<servlet-class>Second</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Teja</servlet-name>

<url-pattern>/hello</url-pattern>

</servlet-mapping>

</web-app>

 Execution:-

 Javac –cp e:\path\servlet-api.jar Second.java

 localhost:2000/project2/hello

Output:--

84
3.Write a servlet application program by extending http servlet class

 Directory structure:-

85
 Third.java:--

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Third extends HttpServlet

public void doGet(HttpServletRequest req,HttpServletResponse res)throws


IOException,ServletException

res.setContentType("text/html");

PrintWriter pw=res.getWriter();

pw.print("<html><body>");

pw.print("<b>Welcome to Pvpsit</b>");

pw.print("</body></html>");

 Web.xml:--

86
<web-app>

<servlet>

<servlet-name>Teja</servlet-name>

<servlet-class>Third</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Teja</servlet-name>

<url-pattern>/PVPSIT</url-pattern>

</servlet-mapping>

</web-app>

 Execution:--

 Javac –cp e:\path\servlet-api.jar Third.java

 localhost:2000/project3/PVPSIT

Output:--

87
4.Write a servlet application program for life cycle of a servlet

 Directory Structure:--

88
 LifeCycle.java:--

import java.io.*;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class LifeCycle extends HttpServlet

public LifeCycle()

System.out.println("Default constructor");

public void init(ServletConfig config)

89
System.out.println("Init method...!”);

public void service(HttpServletRequest req,HttpServletResponse res)throws


ServletException,IOException

res.setContentType("text/html");

PrintWriter pw=res.getWriter();

pw.println("LifeCycle of a service");

pw.close();

public void destroy()

System.out.println("Am from destroy method:");

 Web.xml:--

<web-app>

<servlet>

<servlet-name>Teja</servlet-name>

<servlet-class>Second</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Teja</servlet-name>

<url-pattern>/hello</url-pattern>

</servlet-mapping>

90
</web-app>

 Execution:--

 Javac –cp e:\path\servlet-api.jar LifeCycle.java

 localhost:2000/project4/WT

Output:--

91
EXERCISE-10

2. Write an Servlet Application program for ServletRequest Interface or HTML to Servlet


Program Communication.

 Directory Structure:

92
 SumServlet.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class SumServlet extends HttpServlet

public void doGet(HttpServletRequest req,HttpServletResponse res)throws


ServletException,IOException

int x,y,sum;

x=Integer.parseInt(req.getParameter("fno"));

y=Integer.parseInt(req.getParameter("sno"));

sum=x+y;

93
res.setContentType("text/html");

PrintWriter pw=res.getWriter();

pw.println("<html><body>");

pw.println("result is"+sum);

pw.println("</html></body>");

pw.close();

 Sum.Html

<html>

<head>

<title>First server</title>

</head>

<h2 align="center">Servlet Request</h2>

<form action="sumurl" method="get">

<center>

<table width="20%";

<tr>

<td>First Number</td>

<td><input type="text" name="fno" size="10"</td>

</tr>

<tr>

<td>Second Number</td>

<td><input type="text" name="sno" size="10"></td>

</tr>

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

<td>

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

94
</td>

</tr>

</table>

</center>

</form>

</body>

</html>

 Web.xml:--

<web-app>

<servlet>

<servlet-name>ab</servlet-name>

<servlet-class>SumServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>ab</servlet-name>

<url-pattern>/sumurl</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>sum.html</welcome-file>

</welcome-file-list>

</web-app>

 Execution:

 Javac –cp e:\path\servlet-api.jar First.java

 localhost:2000/proj5/ sum.html

Output:--

95
2. Write an Servlet Application program for HTML-SERVLET-DATABASE Communication.

 Directory Structure:

96
 register.java:--

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class register extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String n=req.getParameter("uname");
String p=req.getParameter("upass");
String e=req.getParameter("uemail");
String c=req.getParameter("ucountry");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","password");

97
PreparedStatement ps=con.prepareStatement("insert into registeruser
values(?,?,?,?)");
ps.setString(1,n);
ps.setString(2,p);
ps.setString(3,e);
ps.setString(4,c);
int i=ps.executeUpdate();
if(i>0)
out.print("you r succesfully registered");
}catch(Exception e2)
{
System.out.println(e2);
}
out.close();
}
}

 Register.html:-

<html>
<body>
<form action="servlet/register" method="post">
name:<input type="text" name="uname"/><br/><br/>
password:<input type="password" name="upass"/><br/><br/>
email id:<input type="text" name="uemail"/><br/><br/>
country:<select name="ucountry">
<option>india</option>
<option>pakisthan</option>
<option>others</option>
</select>
</br></br>
<input type="submit" value="register"/>
</form>
</body>
</html>

 Web.xml:--

<web-app>

<servlet>

<servlet-name>reg</servlet-name>

<servlet-class>register</servlet-class>

</servlet>

98
<servlet-mapping>

<servlet-name>reg</servlet-name>

<url-pattern>/register</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>register.html</welcome-file>

</welcome-file-list>

</web-app>

 Execution:-

 Javac –cp e:\path\servlet-api.jar Second.java

 localhost:2000/proj6/register.hml

Output:--

99
3.Write a servlet application program for working with initialization of parameters

 Directory structure:-

100
 DemoServlet.java:--

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
public class demoservlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
IOException,ServletException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
ServletConfig config=getServletConfig();
String driver=config.getInitParameter("driver");
out.print("driver is "+driver);
out.close();
}
}

 Web.xml:--

<web-app>

<servlet>

101
<servlet-name>demoservlet</servlet-name>

<servlet-class>demoservlet</servlet-class>

<init-param>

<param-name>driver</param-name>

<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>demoservlet</servlet-name>

<url-pattern>/servlet</url-pattern>

</servlet-mapping>

</web-app>

 Execution:--

 Javac –cp e:\path\servlet-api.jar Third.java

 localhost:2000/proj7/servlet

Output:--

102
3.Write an Servlet Application program for Request Dispatcher Interface

 Directory Structure:

103
v

 WelcomeServlet.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class WelcomeServlet extends HttpServlet

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String n=request.getParameter("userName");

out.print("Welcome "+n);

104
}

 Login.Java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

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

String n=request.getParameter("userName");
String p=request.getParameter("userPass");

if(p.equals("servlet")){
RequestDispatcher rd=request.getRequestDispatcher("servlet2");
rd.forward(request, response);
}
else{
out.print("Sorry UserName or Password Error!");
RequestDispatcher rd=request.getRequestDispatcher("/index.html");
rd.include(request, response);

}
}

 Index.html

<html>
<head>
</head>
<body>
<form action="servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
Password:<input type="password" name="userPass"/><br/>
<input type="submit" value="login"/>
</form>
</body>

105
</html>

 Web.xml:--

<web-app>

<servlet>

<servlet-name>Login</servlet-name>

<servlet-class>Login</servlet-class>

</servlet>

<servlet>

<servlet-name>WelcomeServlet</servlet-name>

<servlet-class>WelcomeServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Login</servlet-name>

<url-pattern>/servlet1</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>WelcomeServlet</servlet-name>

<url-pattern>/servlet2</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

</web-app>

 Execution:

 Javac –cp e:\path\servlet-api.jar First.java

 localhost:2000/proj8/ index.html

106
Output:--

107
108
3.Write a servlet application program for working with initialization of context parameters

 Directory structure:-

109
 DemoServlet.java:--

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
public class demoservlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
IOException,ServletException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
ServletContext sc=getServletContext();
String driver=sc.getInitParameter("driver");
out.print("driver is "+driver);
out.close();
}
}

 Web.xml:--

<web-app>

<context-param>

110
<param-name>driver</param-name>

<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>

</context-param>

<servlet>

<servlet-name>demoservlet</servlet-name>

<servlet-class>demoservlet</servlet-class>

<init-param>

<param-name>driver</param-name>

<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>demoservlet</servlet-name>

<url-pattern>/servlet</url-pattern>

</servlet-mapping>

</web-app>

 Execution:--

 Javac –cp e:\path\servlet-api.jar Third.java

 localhost:2000/proj7/servlet

Output:--

111
Exercise-11

JAVA-BEANS

 SAMPLE BEAN

Aim: write a program to implement sample java bean.

 Creating directory structure.

C:>Beans

demo

112
sunw

demo

bean.mft cse

SimpleBean.java

package sunw.demo.cse;

import java.awt.*;

import java.io.Serializable;

public class SimpleBean extends Canvas implements Serializable

public SimpleBean()

setSize(60,40);

setBackground(Color.red);

Bean.mft

Manifest-Version: 1.0

Java-Bean: True

Name: sunw/demo/cse/ SimpleBean.class

Compilation: javac SimpleBean.java

Java simpleBean

Creating jar file:

C:Beans\demo>jar cvfm cse.jar bean.mft sunw\demo\cse\*.class

Output:--

113
 COLOUR BEAN

Aim:write a bean program create a color bean with ellipse .The color of the area should be
changed dynamically for everymouse click.

 Creating directory structure

e:>Beans

wtlab

org

cse

two.mft sec1

Program:

package org.cse.sec1;

import java.awt.*;

import java.awt.event.*;

public class MyColor extends Canvas {

114
transient private Color color;

private boolean rectangular;

public MyColor() {

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

115
}

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

Two.mft

Manifest-Version: 1.0

Java-Bean: True

Name: org/cse/sec1/MyColor.class

Compilation:

 javac MyColor.java
 Java Mycolor

Creating jar file:

 jar cvfm mycolor.jar two.mft org/cse/sec1/*.class

116
Output:--

117
Exercise-12

Aim:write a sample jsp program.

<html>

<body>

<% out.print(2*5); %>

</body>

</html>

Output:---

10

Exercise-13

AIM: Write a JSP which does the following job: Insert the details of the 3 or 4 users who

118
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.
CREATING THE TABLE:
Create table registration_table(id int(40), name varchar2(50) not null, password varchar2(50),
email varchar2(50) not null, phone varchar2(10) not null, Primary key(id));
SOURCE CODE:
<%@ page import="java.lang.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
Connection conn=null; ResultSet rs=null; Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:week10,’root’,’system’”);
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 intoregistration_table(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_table(name,password,email,phone)values('"+Studname+"','"+Studpass+"','"+Studem
ail+

"','"+Studphone+"')");

119
}
else if(Studname.equals("user3")&&Studpass.equals("pwd3"))
{
out.write("Welcome "+Studname);
stmt.executeUpdate("insert into
registration_table(name,password,email,phone)values('"+Studname+"','"+Studpass+"','"+Studem
ail+
"','"+Studphone+"')");
}
else if(Studname.equals("user4")&& Studpass.equals("pwd4"))
{
out.write("Welcome "+Studname);
stmt.executeUpdate("insert into registration_table(name,password,email,phone)
values('"+Studname+"','"+Studpass+"','"+Studemail+"','"+Studphone+"')");
}
else
{
out.write("\n You have entered invalid usemame/password,try again!!!");
}

out.write("<br/> <br/>");
out.write("\n Current Records are ... ");
rs=stmt.executeQuery("select * from registration_table");
%>
<html>
<body>
<center>
<h2>Student List</h2>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td> <b>No</b> </td>
<td> <b> User Name</b> </td>
<td> <b>E-Mail</b>
</td> <td> <b>Phone</b> </td>

120
</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
();
se();
conn.close
();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title> Student Registartion Demo </title>
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.Studname.value.length==0)
{

121
alert("Please,fill up the remaining
information!!"); Form_obj.Studname.focus();

return false;
}
if(Form_obj.Studemail.value.length==0)
{
alert("Please,fill up the remaining
information!!");
Form_obj.Studaddress.focus();

return false;
}
if((Form_obj.Studphone.value.length==0)||(Form_obj.Studphone.value.lengt h>10))
{
alert("Invalid Phone number Entry, fill up once
again!!"); Form_obj.Studphone.focus();

return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form action="Registration_Form1.jsp" method="post" name="entry"
onSubmit="return validation(this)">

<input type="hidden" value="list" name ="action">


<table border="3" cellpadding="0" cellspacing="0">
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Student Entry Form</h2></td></tr>
<tr>

122
<td colspan="2" >&nbsp;</td></tr>
<tr>
<td>Student Name:</td>
<td> <input name="Studname" type= "text" size="50"></td></tr>
<tr>
<td>Student Password:</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>
<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></td></tr>
</table></form>
</center>
</body>
</html>
<%}%>

Output:

123
124

You might also like