AjWt Lab
AjWt Lab
Program:--
<html>
<head>
<title>headings</title>
</head>
<body bgcolor='skyblue'>
</body>
</html>
Output:- -
1
2a.Write an HTML program for Link Tags
<html>
<head>
<title>Link</title>
</head>
<h1 align="justify">LINK</h1>
</body>
</html>
Petrol.html
<html>
<body>
<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>
</body>
</html>
Program:--(anchor prgm)
<html>
<head>
<title>anchor tag</title>
</head>
</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">
</body>
</html>
Output:
6
3b.Write an HTML program for pre Tags.
<html>
<head>
<title>Pre tag</title>
</head>
<body>
<h1 align="center">Pre-Tag</h1>
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">
<center><img src="http://www.pageresource.com/wallpapers/wallpaper/flowers-butterflies-
pictures-images_1664656.jpg" height="30%"width="30%"></center>
<br>
</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">
<br>
<br>
<br>
<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
Program:--
<html>
<head>
<title>Frame</title>
</head>
<frameset rows="50%,*">
<frame src="flag.html">
<frameset cols="50%,*">
</frameset>
</html>
Output:--
11
7. Write an HTML program for Form Tags
Program:--
<html>
<head>
<title>Forms</title>
<center>
<h1>Forms creation</h1>
</head>
<fieldset>
Education:</br>
Gender:</br>
Address:</br>
<br/>
birthday:</br>
</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">
<caption>
</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> </td>
</tr>
<tr align="center">
<td><b>Tue</b></td>
<td>CN</td>
<td>SS</td>
<td>SE</td>
<td>DAA(T)</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>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> </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>
<th>SUBJECT NAME</th>
<tr align="center">
<td>WEBTECHNOLOGIES</td>
<td>KVENKATESH/RAJESH/KN DIVYA</td>
</tr>
<tr align="center">
<td>WEBTECHNOLOGIES LAB</td>
</tr>
<tr align="center">
<td>COMPUTER NETWORKS</td>
<td>B.SRINIVAS RAO/SVISHNUVARDHAN/
DLOKESHSAIKUMAR</td>
</tr>
<tr align="center">
17
MINING</td>
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>
</tr>
<tr align="center">
</tr>
<tr align="center">
K VENKATESH/V RAJESH</td>
</tr>
<tr align="center">
<td>SOFT SKILLS</td>
<td>L SUDHEERA</td>
</tr>
<<tr align="center">
<td>SEMINAR</td>
</tr>
18
<table>
</body> </html>
Output:--
19
Output:--
20
Exercise-3
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">
</frameset>
</frameset>
</html>
Login:
<html>
<h1 align="center">login</h1>
<tr align="center">
<td align="right"><h3>username</td>
</form></td>
</tr>
<tr align="center">
<td align="right"><h3>password</td>
21
<form></td>
</tr>
<tr align="center">
</td>
</td>
</tr>
</table>
</body>
</html>
Output:--
22
Registration:--
<html>
<head>
<title>registration</title>
</head>
<body>
<tr>
<td>
<form method="post">
<br>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<b>DOB</b>::DD<select>
<optgroup>
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>
</optgroup>
</td>
<td>
MM<select>
<optgroup>
</optgroup>
</td>
<td>
DD<select>
<optgroup>
</optgroup>
</td>
</table>
24
</td>
</tr>
<tr>
<td>
<form method="post">
<br>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td><b>Address:</b></td>
</textarea></td>
<br>
</td>
</tr>
<tr>
<td>
<form method="post">
<br>
</td>
</tr>
<tr>
<td>
<form method="post">
<br>
25
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<form>
</form>
</td></tr>
</table>
</td></tr>
<tr>
<td>
<form method="post">
<form method="post">
</td>
</tr>
</table>
</table>
<table>
<tr><td>
<img src="13.gif"></td>
<td>
</td></tr>
26
</table>
</body>
</html>
Output:--
27
Catalogue:
<html>
<head>
<title>catalogue</title>
</head>
<body>
<th bgcolor="violet"><h3><i>Publisher</th>
<th bgcolor="violet"><h3><i>Price</th>
<td>
<td><h3>Pankaj sharma</td>
<td><h3>Katson books</td>
<td><h3>500</td>
</tr>
<td>
<td><h3>Kentech</td>
<td><h3>Dreamtech press</td>
<td><h3>2000</td>
</td>
</tr>
<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>
<td>
<td><h3>Ian.H.Witlen</td>
<td><h3>M.K Publications</td>
<td><h3>2100</td>
</tr>
<td>
<td><h3>Gaurav Giridhar</td>
<td><h3>Katson books</td>
<td><h3>680</td>
</tr>
<td>
<td><h3>Abraham</td>
<td><h3>wisley publications</td>
<td><h3>800</td>
</tr>
<td>
<td><h3>Pradeep K Sinha</td>
<td><h3>E.E.E</td>
29
<td><h3>2010</td>
</tr>
<td>
<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>
</td>
</tr>
</table>
</body>
</html>
Output:--
30
Add to Cart:--
<html>
<head>
</head>
<body bgcolor="59ff52">
</body>
</html>
Cart.html:--
<html>
<head>
31
<title>active cart button</title>
</head>
<body bgcolor="59ff52">
<h1>ADD TO CART</h1>
<br>
<br>
</body>
</html>
Output:--
32
CSE:----
<html>
<head>
<title>catalogue</title>
</head>
<th><h3><i>cover page</th>
33
<th><h3><i>Author name</th>
<th><h3><i>Publisher</th>
<th><h3><i>Price</th>
<tr align="center">
<td>
<td><h3>Pankaj sharma</td>
<td><h3>Katson books</td>
<td><h3>500</td>
</tr>
<tr align="center">
<td>
<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
36
Program:
<html>
<body>
<h1 style="color:blue;margin-left:30px;">welcome</h1>
<p>normal text</p>
</body>
</html>
Output:--
Program:
<html>
<head>
<style>
h1 {
37
color:black;
margin-left:10px;
}
</style>
</head>
<body>
<h1>Welcome</h1>
<p>Welcome</p>
</body>
</html>
Output:---
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:---
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
41
Program:
<html>
<head>
</head>
<body bgcolor="skyblue">
<script type="text/javascript" language="javascript">
document.write("hai hello");
</script>
</body>
</html>
Output:---
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:--
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:--
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">
<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>
<ul>
60
<li><label for="passid">Password:</label></li>
<li><label for="username">Name:</label></li>
<li><label for="country">Country:</label></li>
<li><select name="country">
<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="email">Email:</label></li>
<li><label id="gender">Sex:</label></li>
<li><label>Language:</label></li>
<li><label for="desc">About:</label></li>
</ul>
</form>
61
</body>
</html>
validation.js:
function formValidation()
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)
uid.focus();
return false;
return true;
function passid_validation(passid,mx,my)
passid.focus();
63
return false;
return true;
function allLetter(uname)
if(uname.value.match(letters))
return true;
else
uname.focus();
return false;
function alphanumeric(uadd)
if(uadd.value.match(letters))
return true;
else
64
uadd.focus();
return false;
function countryselect(ucountry)
if(ucountry.value == "Default")
ucountry.focus();
return false;
else
return true;
function allnumeric(uzip)
if(uzip.value.match(numbers))
return true;
else
uzip.focus();
65
return false;
function ValidateEmail(uemail)
if(uemail.value.match(mailformat))
return true;
else
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
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;
float: left;
margin-bottom: 10px;
form textarea {
float: left;
width: 350px;
height: 150px;
[type="submit"] {
clear: left;
font-size:18px
p{
margin-left: 70px;
font-weight: bold;
68
Output:---
69
EXERCISE-7
program:
2.External DTD:
Program:
Note.DTD:
Output:--
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:--
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;
try {
DocumentBuilderFactory dbFactory
= DocumentBuilderFactory.newInstance();
doc.getDocumentElement().normalize();
71
System.out.println("Root element :"
+ doc.getDocumentElement().getNodeName());
System.out.println("----------------------------");
+ nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
.item(0)
.getTextContent());
} catch (Exception e) {
e.printStackTrace();
5.XSLT:
Program:
<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>
<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:
73
<!-- Edited by XMLSpy® -->
<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
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();
}
}
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();
}
}
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);
}
}
}
Program:
Import java.sql.*;
Import java.util.*;
class callstmt
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","admin");
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
}
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.*;
ServletConfig config=null;
this.config=config;
System.out.println("Servlet is initialized");
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>");
System.out.println("Servlet is destroyed");
return config;
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:
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.*;
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:-
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.*;
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:--
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 LifeCycle()
System.out.println("Default constructor");
89
System.out.println("Init method...!”);
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("LifeCycle of a service");
pw.close();
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:--
localhost:2000/project4/WT
Output:--
91
EXERCISE-10
Directory Structure:
92
SumServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
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>
<center>
<table width="20%";
<tr>
<td>First Number</td>
</tr>
<tr>
<td>Second Number</td>
</tr>
<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:
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:-
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:--
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.*;
response.setContentType("text/html");
String n=request.getParameter("userName");
out.print("Welcome "+n);
104
}
Login.Java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
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:
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:--
localhost:2000/proj7/servlet
Output:--
111
Exercise-11
JAVA-BEANS
SAMPLE BEAN
C:>Beans
demo
112
sunw
demo
bean.mft cse
SimpleBean.java
package sunw.demo.cse;
import java.awt.*;
import java.io.Serializable;
public SimpleBean()
setSize(60,40);
setBackground(Color.red);
Bean.mft
Manifest-Version: 1.0
Java-Bean: True
Java simpleBean
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.
e:>Beans
wtlab
org
cse
two.mft sec1
Program:
package org.cse.sec1;
import java.awt.*;
import java.awt.event.*;
114
transient private Color color;
public MyColor() {
addMouseListener(new MouseAdapter() {
change();
});
rectangular = false;
setSize(200, 100);
change();
return rectangular;
this.rectangular = flag;
repaint();
color = randomColor();
repaint();
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
115
}
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(color);
if(rectangular) {
else {
Two.mft
Manifest-Version: 1.0
Java-Bean: True
Name: org/cse/sec1/MyColor.class
Compilation:
javac MyColor.java
Java Mycolor
116
Output:--
117
Exercise-12
<html>
<body>
</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)">
122
<td colspan="2" > </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