Java Lab Manual

125
VEL TECH Dr.RR and Dr.SR TECHNICAL UNIVERSITY ADVANCED JAVA PROGRAMMING LAB MANUAL BY RAJKUMAR NARAYANAN TTS 1577

Transcript of Java Lab Manual

VEL TECH Dr.RR and Dr.SR TECHNICAL UNIVERSITY

ADVANCED JAVA PROGRAMMING

LAB MANUAL

BY

RAJKUMAR NARAYANAN

TTS 1577

VEL TECH Dr.RR and Dr.SR TECHNICAL UNIVERSITY, AVADI.

ADVANCED JAVA PROGRAMMING LAB MANUAL

Subject Code : PITA05

Faculty Name : Mr.Rajkumar Narayanan

---------------------------------------

Ex-No : 01

Title :DEVELOPING STATIC WEB PAGE

Aim:

To develop static pages (using Only HTML) of an online Bookstore. The pages should resemble: www.amazon.com. The website should contain the following pages.

Home page, Registration and user Login, User Profile Page Books catalog, Shopping Cart, Payment By credit card, Order Conformation.

HOME PAGE

<html> <head> <title>My Web Site</title> </head>

<body>

<table width='102%' cellpadding='0' cellspacing='0' border='0' background="images/inner_part2_bg.jpg" HEIGHT='75'>

<td class='donotprint' align='center'>Welcome to My Web Site </span> </td></tr>

</table>

<table width='*' cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif"">

<tr height=11>

<td background="images/om_top_bg.gif" colspan="3" ></td></tr>

<tr height=11>

<td colspan=3><img src="images/CONTACT.jpg"></td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" colspan="3" ></td></tr>

<tr>

<td background="images/om_bg_panel_blue.gif">

<form name="frm" method="post">

<table cellpadding="0" cellspacing="0" border="0" align="center" >

<tr> <td align="left" >Username: <input name="uname" id="uname" type="text" value="" size="15"></td> </tr>

<tr> <td align="left" >Password: <input name="password" id="password" type="password" size="15">

</td> </tr>

<tr> <td align="right" > <input name="button" type="button" value="Go" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:21;height:22;background-image:url('/images/go.gif')"align="absmiddle"/>

</td> </tr>

<tr><td align="left" valign="bottom"><a href="newuserreg.html" >New User Registration</a></td> </tr>

<tr><td>&nbsp;&nbsp;</td></tr>

<tr><td height="*" align="center" valign="bottom" ><a href="Contact.html">Contact</a></td></tr>

</table> </form> </td>

<td align="center" valign="top" >

<table background="images/om_bg_panel_blue.gif"><tr ><td valign="top"><b><font color="blue"> About the WebSite </font></b><br><br>

My Web Site is an Intelligent Web based Project management system for the Engineers.

Experts with years of experience in management and managing remote/ offshore projects built My Web Site.<br><br><br><br><hr></td></tr>

<tr valign="bottom" align="center"><td><br>Best Viewed with 1024x768 resolution and Microsoft Internet Explorer 6.0 or later<br></td></tr></table>

</td>

<td background="images/inner_part2_bg.jpg" align="center">Client Speak <br><img src="images/img_clientspeak.jpg"/></td>

</td></tr>

<tr height=11><td background="images/om_top_bg.gif" colspan="3" ></td></tr>

</table> </body> </html>

CONTACT

<html> <head> <title>My Web Site - Contact us</title> </head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td colspan="3" background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My Web Site </span></td></tr>

</table>

<table width="98%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr>

<tr height=11>

<td ><img src="images/CONTACT.jpg"></td></tr>

<tr >

<td background="images/om_bg_panel_blue.gif" align="center" valign="top" >

<b><font color="blue"> Contact</font></b><br><br>

President<br> My Web Site<br> Avadi<br> Chennai

</tr>

<tr><td height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>

</td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr> </table> </body> </html>

USER PAGE

<html> <head> <title>My Web Site - Contact us</title> </head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td colspan="3" background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My WebSite </span></td></tr>

</table>

<table width="98%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11>

<td background="images/om_top_bg.gif" ></td></tr>

<tr height=11>

<td ><img src="images/CONTACT.jpg"></td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" ></td></tr>

<tr >

<td background="images/om_bg_panel_blue.gif" align="center" valign="top" >

<b><font color="blue"> Welcome user</font></b><br><br>

Welcome to world of Project Management.<br><br>

My Web Site is an Intelligent Web based Project management system for the Engineers.

Experts with years of experience in management and managing remote/ offshore projects built My Web Site.

</tr>

<tr><td height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>

</td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" >

</td> </tr> </table> </body> </html>

USER REGISTRATION

<html> <head> <title>My Web Site - New User Registration</title> </head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" height='103'>

<tr><td>

<td background="images/inner_part2_bg.jpg" align='center'>Welcome to My Web Site </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11>

<td colspan='2' background="images/om_top_bg.gif" >

</td></tr>

<tr> <td colspan='2' align="center" valign="top" >

<b><font color="blue">New User Registration</font></b><br><br> </tr>

<form name="frm" method="post">

<tr> <td width='25%' align="right" > Username:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="uname" id="uname" type="text" value="" ><font color='red'>&nbsp;*&nbsp;</font>

<font color='blue' size='2'>(Minimum 8 characters)</font>

</td> </tr>

<tr> <td width='25%' align="right" >Password:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="password" id="password" type="password" ><font color='red'>&nbsp;*&nbsp;</font>

<font color='blue' size='2'>(Minimum 6 characters)</font>

</td> </tr>

<tr> <td width='25%' align="right" >Confirm Password:&nbsp;&nbsp;</td>

<td width='75%' align="left"> <input name="cpassword" id="cpassword" type="password"><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='100%' align="right" colspan='2'> <hr>

</td> </tr>

<tr> <td width='25%' align="right" > Name:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mname" id="mname" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Address:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="maddress" id="maddress" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > City:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mcity" id="mcity" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > State:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mstate" id="mstate" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Country:&nbsp;&nbsp;</td>

<td width='75%' align="left"> <select name="cbo_country" size="1" >

<option value="">- Choose a country -</option>

<option value='AR'>ARGENTINA </option><option value='AU'>AUSTRALIA </option><option value='AT'>AUSTRIA </option><option value='BH'>BAHRAIN </option><option value='BB'>BARBADOS </option><option value='BY'>BELARUS </option><option value='BE'>BELGIUM </option><option value='BZ'>BELIZE </option><option value='BA'>BOSNIA </option><option value='BR'>BRAZIL </option><option value='BG'>BULGARIA </option><option value='KH'>CAMBODIA </option><option value='CA'>CANADA </option><option value='CL'>CHILE

</option><option value='CN'>CHINA </option><option value='CO'>COLOMBIA </option><option value='CR'>COSTA RICA </option><option value='HR'>CROATIA </option><option value='CZ'>CZECH REPUBLIC </option><option value='DO'>DOMINICAN REPUBLIC </option><option value='EC'>ECUADOR </option><option value='EG'>EGYPT </option><option value='SV'>EL SALVADOR </option><option value='EE'>ESTONIA </option><option value='FI'>FINLAND </option><option value='FR'>FRANCE </option><option value='PF'>FRENCH POLYNESIA </option><option value='DE'>GERMANY </option><option value='GH'>GHANA </option><option value='GI'>GIBRALTAR </option><option value='GR'>GREECE </option><option value='GT'>GUATEMALA </option><option value='HN'>HONDURAS </option><option value='HK'>HONG KONG </option><option value='HU'>HUNGARY </option><option value='IS'>ICELAND </option><option value='IN'>INDIA </option><option value='ID'>INDONESIA </option><option value='IR'>IRAN </option><option value='IQ'>IRAQ </option><option value='IE'>IRELAND </option><option value='IL'>ISRAEL </option><option value='IT'>ITALY </option><option value='JM'>JAMAICA </option><option value='JP'>JAPAN </option><option value='JO'>JORDAN </option><option value='KZ'>KAZAKHSTAN </option><option value='KE'>KENYA </option><option value='KW'>KUWAIT </option><option value='LV'>LATVIA </option><option value='LB'>LEBANON </option><option value='LY'>LIBYA </option><option value='LT'>LITHUANIA </option><option value='LU'>LUXEMBOURG </option><option value='MO'>MACAU </option><option value='MY'>MALAYSIA </option><option value='MQ'>MARTINIQUE </option><option value='MU'>MAURITIUS </option><option value='MX'>MEXICO </option><option value='MA'>MOROCCO </option><option value='NP'>NEPAL </option><option value='NL'>NETHERLANDS </option><option value='NZ'>NEW ZEALAND </option><option value='NI'>NICARAGUA </option><option value='NG'>NIGERIA </option><option value='PK'>PAKISTAN </option><option value='PA'>PANAMA </option><option value='PE'>PERU </option><option value='PH'>PHILIPPINES </option><option value='PL'>POLAND </option><option value='PT'>PORTUGAL </option><option value='QA'>QATAR</option><option value='RO'>ROMANIA </option><option value='RU'>RUSSIAN FEDERATION </option><option value='SA'>SAUDIA ARABIA </option><option value='CS'>SERBIA AND MONTENEGRO </option><option value='SG'>SINGAPORE </option><option value='SK'>SLOVAK REPUBLIC </option><option value='SI'>SLOVENIA </option><option value='ZA'>SOUTH AFRICA </option><option value='ES'>SPAIN </option><option value='SD'>SUDAN </option><option value='SE'>SWEDEN </option><option value='CH'>SWITZERLAND </option><option value='SY'>SYRIAN ARAB REPUBLIC </option><option value='TW'>TAIWAN </option><option value='TZ'>TANZANIA </option><option value='TH'>THAILAND </option><option value='TN'>TUNISIA </option><option value='TR'>TURKEY </option><option value='UG'>UGANDA </option><option value='UA'>UKRAINE </option><option value='AE'>UNITED ARAB EMIRATES </option><option value='UK'>UNITED KINGDOM </option><option value='US'>UNITED STATES </option><option value='UZ'>UZBEKISTAN </option><option value='VE'>VENEZUELA </option><option value='VN'>VIETNAM </option><option value='ZW'>ZIMBABWE</option>

</select><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Zip/Pin code:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mpincode" id="mpincode" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > User Type:&nbsp;&nbsp;</td>

<td width='75%' align="left"><select name="cbo_utype" id="cbo_utype" >

<option value="">- Select User Type -</option>

<option value="ordinary">Member</option>

<option value="premium">Premium Member</option>

<option value="lifetime">LifeTime Member</option>

</select><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='100%' align="right" colspan='2'> <hr>

</td> </tr>

<tr>

<td align="left" width='35%' ><a href="homepage.html">Home</a>&nbsp;&nbsp;

<font color='red'>&nbsp;*</font> - denotes mandarory fields</td>

<td width='65%' align="right" >

<input name="button" type="button" value="Save" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:50;height:22"/>

&nbsp;&nbsp;</td> </tr>

</form> </table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr> </table> </body> </html>

OUTPUT

HOME PAGE

CONTACT

USER REGISTRATION

RESULT:

Thus the program has been executed and completed successfully.

Ex-No: 2

Title : VALIDATING REGISTRATION,PAYMENT BY CREDIT CARD

Aim:

To validate the Registration, user login, user profile and payment by credit card pages using JavaScript.

HOME PAGE

<html>

<head>

<title>My Web Site</title>

<script language="JavaScript" type="text/JavaScript">

function checklogin()

{

var unameblank=false;

var pwdblank=false;

if(frm.uname.value.length==0)

unameblank=true;

if(frm.password.value.length==0)

pwdblank=true;

if(unameblank==true && pwdblank==true)

{ alert("Sorry, Username and password can't be left blank.");

frm.uname.focus(); }

else if(unameblank==true)

{ alert("Sorry, Username can't be left blank.");

frm.uname.focus(); }

else if(pwdblank==true)

{ alert("Sorry, Password can't be left blank.");

frm.password.focus(); }

else

{ frm.action="userPage.html";

frm.submit(); }

}

function login()

{ if(window.event.keyCode==13)

checklogin(); }

</script> </head> <body>

<table width='100%' cellpadding='0' cellspacing='0' border='0' background="images/inner_part2_bg.jpg" HEIGHT='75'>

<td class='donotprint' align='center'>Welcome to My Web Site </span> </td></tr>

</table>

<table width='*' cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif"">

<tr height=11>

<td background="images/om_top_bg.gif" colspan="3" ></td></tr>

<tr height=200>

<td colspan="3" background="images/books1.jpg" ></td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" colspan="3" ></td></tr>

<tr>

<td background="images/om_bg_panel_blue.gif">

<form name="frm" method="post">

<table cellpadding="0" cellspacing="0" border="0" align="center" >

<tr> <td align="left" >Username: <input name="uname" id="uname" type="text" value="" size="15"></td> </tr>

<tr> <td align="left" >Password: <input name="password" id="password" onkeypress="javascript:login()" type="password" size="15">

</td> </tr>

<tr> <td align="right" > <input name="button" type="button" onClick="javascript:checklogin();" value="Go" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:21;height:22;background-image:url('/images/go.gif')"align="absmiddle"/>

</td> </tr>

<tr><td align="left" valign="bottom"><a href="newuserreg.html" >New User Registration</a></td> </tr>

<tr><td>&nbsp;&nbsp;</td></tr>

<tr><td height="*" align="center" valign="bottom" ><a href="Contact.html">Contact</a></td></tr>

</table> </form> </td>

<td align="center" valign="top" >

<table background="images/om_bg_panel_blue.gif"><tr ><td valign="top"><b><font color="blue"> About the WebSite </font></b><br><br>

My Web Site is an Intelligent Web based Project management system for the Engineers.

Experts with years of experience in management and managing remote/ offshore projects built My Web Site.<br><br><br><br><hr></td></tr>

<tr valign="bottom" align="center"><td><br>Best Viewed with 1024x768 resolution and Microsoft Internet Explorer 6.0 or later<br></td></tr></table>

</td>

<td background="images/inner_part2_bg.jpg" align="center">Client Speak <br><img src="images/img_clientspeak.jpg"/></td>

</td></tr>

<tr height=11><td background="images/om_top_bg.gif" colspan="3" ></td></tr>

</table> </body> </html>

CATALOG

<html>

<head>

<title>My Web Site - Contact us</title>

</head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td colspan="3" background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My WebSite </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr height=11>

<td background="images/om_top_bg.gif" ></td></tr>

<tr height=150>

<td background="images/books1.jpg" ></td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" ></td></tr>

<tr>

<td align="center" valign="top" background="images/om_bg_panel_blue.gif">

<b><font color="blue"> Books Catalog</font></b><br></td></tr>

<tr><td>

<script type="text/javascript">

if (window.XMLHttpRequest)

{ xhttp=new XMLHttpRequest(); }

else // Internet Explorer 5/6

{ xhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

xhttp.open("GET","cd_catalog.xml",false);

xhttp.send("");

xmlDoc=xhttp.responseXML;

document.write("<table border='1'>");

document.write("<tr><td>TITLE</td><td>AUTHOR</td><td>PRICE</td><td>YEAR</td><tr>");

var x=xmlDoc.getElementsByTagName("CD");

for (i=0;i<x.length;i++)

{

document.write("<tr><td>");

document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);

document.write("</td><td>");

document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);

document.write("</td><td align='right'>");

document.write(x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue);

document.write("$</td><td>");

document.write(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);

document.write("</td></tr>");

}

document.write("</table>");

</script>

<hr>

</td></tr>

<tr><td height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>

&nbsp;&nbsp;&nbsp;&nbsp;<a href="contact.html">Contact</a>

</td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr>

</table> </body> </html>

CONTACT

<html>

<head>

<title>My Web Site - Contact us</title>

</head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td colspan="3" background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My Web Site </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr>

<tr height=250>

<td background="images/books1.jpg" ></td></tr>

<tr >

<td background="images/om_bg_panel_blue.gif" align="center" valign="top" >

<b><font color="blue"> Contact</font></b><br><br>

President<br>

My Web Site<br>

Avadi<br>

Chennai

</tr>

<tr><td height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>

</td></tr>

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr>

</table> </body> </html>

USER REGISTRATION

<html>

<head>

<title>My Web Site - New User Registration</title>

<script language="JavaScript" type="text/JavaScript">

function Validate()

{

var errflag=false;

if(frm.uname.value.length<8)

{ alert("Sorry, Username must be minimum 8 chars.");

errflag=true; frm.uname.focus(); }

else if(frm.password.value.length<6)

{ alert("Sorry, Password must be minimum 6 chars.");

errflag=true; frm.password.focus(); }

else if(frm.cpassword.value!=frm.password.value)

{ alert("Sorry, Confirm Password must be as Password.");

errflag=true; frm.password.focus();

}

else if(frm.mname.value.length==0)

{ alert("Sorry, Name can't be left blank.");

errflag=true; frm.mname.focus(); }

else if(frm.maddress.value.length==0)

{ alert("Sorry, Address can't be left blank.");

errflag=true; frm.maddress.focus(); }

else if(frm.mcity.value.length==0)

{ alert("Sorry, City can't be left blank.");

errflag=true; frm.mcity.focus(); }

else if(frm.mstate.value.length==0)

{ alert("Sorry, State can't be left blank.");

errflag=true; frm.mstate.focus(); }

else if(frm.cbo_country.value.length==0)

{ alert("Sorry,Select a Country.");

errflag=true;

frm.cbo_country.focus();

}

else if(frm.mpincode.value.length==0)

{ alert("Sorry, Pincode can't be left blank.");

errflag=true; frm.mpincode.focus(); }

else if(frm.cbo_utype.value.length==0)

{ alert("Sorry,Select a User Type."); errflag=true; frm.cbo_utype.focus(); }

if(errflag==false)

{

if(frm.cbo_utype.value=="ordinary")

{ frm.action="payfeeo.html"; frm.submit(); }

else if(frm.cbo_utype.value=="premium")

{ frm.action="payfeep.html"; frm.submit(); }

else if(frm.cbo_utype.value=="lifetime")

{ frm.action="payfeel.html"; frm.submit(); } } }

</script> </head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" height='103'>

<tr><td>

<td background="images/inner_part2_bg.jpg" align='center'>Welcome to My Web Site </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11>

<td colspan='2' background="images/om_top_bg.gif" >

</td></tr>

<tr> <td colspan='2' align="center" valign="top" >

<b><font color="blue">New User Registration</font></b><br><br>

</tr>

<form name="frm" method="post">

<tr> <td width='25%' align="right" > Username:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="uname" id="uname" type="text" value="" ><font color='red'>&nbsp;*&nbsp;</font>

<font color='blue' size='2'>(Minimum 8 characters)</font>

</td> </tr>

<tr> <td width='25%' align="right" >Password:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="password" id="password" type="password" ><font color='red'>&nbsp;*&nbsp;</font>

<font color='blue' size='2'>(Minimum 6 characters)</font>

</td> </tr>

<tr> <td width='25%' align="right" >Confirm Password:&nbsp;&nbsp;</td>

<td width='75%' align="left"> <input name="cpassword" id="cpassword" type="password"><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='100%' align="right" colspan='2'> <hr>

</td> </tr>

<tr> <td width='25%' align="right" > Name:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mname" id="mname" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Address:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="maddress" id="maddress" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > City:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mcity" id="mcity" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > State:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mstate" id="mstate" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Country:&nbsp;&nbsp;</td>

<td width='75%' align="left"> <select name="cbo_country" size="1" >

<option value="">- Choose a country -</option>

<option value='AR'>ARGENTINA </option><option value='AU'>AUSTRALIA </option><option value='AT'>AUSTRIA </option><option value='BH'>BAHRAIN </option><option value='BB'>BARBADOS </option><option value='BY'>BELARUS </option><option value='BE'>BELGIUM </option><option value='BZ'>BELIZE </option><option value='BA'>BOSNIA </option><option value='BR'>BRAZIL </option><option value='BG'>BULGARIA </option><option value='KH'>CAMBODIA </option><option value='CA'>CANADA </option><option value='CL'>CHILE </option><option value='CN'>CHINA </option><option value='CO'>COLOMBIA </option><option value='CR'>COSTA RICA </option><option value='HR'>CROATIA </option><option value='CZ'>CZECH REPUBLIC </option><option value='DO'>DOMINICAN REPUBLIC </option><option value='EC'>ECUADOR </option><option value='EG'>EGYPT </option><option value='SV'>EL SALVADOR </option><option value='EE'>ESTONIA </option><option value='FI'>FINLAND </option><option value='FR'>FRANCE </option><option value='PF'>FRENCH POLYNESIA </option><option value='DE'>GERMANY </option><option value='GH'>GHANA

</option><option value='GI'>GIBRALTAR </option><option value='GR'>GREECE </option><option value='GT'>GUATEMALA </option><option value='HN'>HONDURAS </option><option value='HK'>HONG KONG </option><option value='HU'>HUNGARY </option><option value='IS'>ICELAND </option><option value='IN'>INDIA </option><option value='ID'>INDONESIA </option><option value='IR'>IRAN </option><option value='IQ'>IRAQ </option><option value='IE'>IRELAND </option><option value='IL'>ISRAEL </option><option value='IT'>ITALY </option><option value='JM'>JAMAICA </option><option value='JP'>JAPAN </option><option value='JO'>JORDAN </option><option value='KZ'>KAZAKHSTAN </option><option value='KE'>KENYA </option><option value='KW'>KUWAIT </option><option value='LV'>LATVIA </option><option value='LB'>LEBANON </option><option value='LY'>LIBYA </option><option value='LT'>LITHUANIA </option><option value='LU'>LUXEMBOURG </option><option value='MO'>MACAU </option><option value='MY'>MALAYSIA </option><option value='MQ'>MARTINIQUE </option><option value='MU'>MAURITIUS </option><option value='MX'>MEXICO </option><option value='MA'>MOROCCO </option><option value='NP'>NEPAL </option><option value='NL'>NETHERLANDS </option><option value='NZ'>NEW ZEALAND </option><option value='NI'>NICARAGUA </option><option value='NG'>NIGERIA </option><option value='PK'>PAKISTAN </option><option value='PA'>PANAMA </option><option value='PE'>PERU </option><option value='PH'>PHILIPPINES </option><option value='PL'>POLAND </option><option value='PT'>PORTUGAL </option><option value='QA'>QATAR</option><option value='RO'>ROMANIA </option><option value='RU'>RUSSIAN FEDERATION </option><option value='SA'>SAUDIA ARABIA </option><option value='CS'>SERBIA AND MONTENEGRO </option><option value='SG'>SINGAPORE </option><option value='SK'>SLOVAK REPUBLIC </option><option value='SI'>SLOVENIA </option><option value='ZA'>SOUTH AFRICA </option><option value='ES'>SPAIN </option><option value='SD'>SUDAN </option><option value='SE'>SWEDEN </option><option value='CH'>SWITZERLAND </option><option value='SY'>SYRIAN ARAB REPUBLIC </option><option value='TW'>TAIWAN </option><option value='TZ'>TANZANIA </option><option value='TH'>THAILAND </option><option value='TN'>TUNISIA </option><option value='TR'>TURKEY </option><option value='UG'>UGANDA </option><option value='UA'>UKRAINE </option><option value='AE'>UNITED ARAB EMIRATES </option><option value='UK'>UNITED KINGDOM </option><option value='US'>UNITED STATES </option><option value='UZ'>UZBEKISTAN </option><option value='VE'>VENEZUELA </option><option value='VN'>VIETNAM </option><option value='ZW'>ZIMBABWE</option>

</select><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Zip/Pin code:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mpincode" id="mpincode" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > User Type:&nbsp;&nbsp;</td>

<td width='75%' align="left"><select name="cbo_utype" id="cbo_utype" >

<option value="">- Select User Type -</option>

<option value="ordinary">Member</option>

<option value="premium">Premium Member</option>

<option value="lifetime">LifeTime Member</option>

</select><font color='red'>&nbsp;*</font>

</td> </tr><tr> <td width='100%' align="right" colspan='2'> <hr>

</td> </tr><tr>

<td align="left" width='35%' ><a href="homepage.html">Home</a>&nbsp;&nbsp;

<font color='red'>&nbsp;*</font> - denotes mandarory fields</td>

<td width='65%' align="right" >

<input name="button" type="button" onClick="javascript:Validate();" value="Save" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:50;height:22"/>

&nbsp;&nbsp;</td> </tr>

</form> </table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr></table> </body> </html>

PAYMENT BY CREDIT CARD

<html>

<head>

<title>My Web Site - Pay User Registration Fee</title>

<script language="JavaScript" type="text/JavaScript">

function Validate()

{

var errflag=false;

var numlength=0;

var usrstr=frm.ccno.value;

var strlength=usrstr.length;

if (strlength==19)

{

for(i=0;i<usrstr.length;i++)

{

if (i==4 || i==9 || i==14)

{ if(usrstr.charCodeAt(i)==46) numlength++; }

else

{ if(usrstr.charCodeAt(i)>47 && usrstr.charCodeAt(i)<58)

numlength++; } }

if(numlength==19)

{ alert("Credit Card Payment Sucessfully Completed.");

frm.action="userpage.html"; frm.submit(); }

else

{ alert("Sorry, Invalid Credit Card Number."); } }

else

{ alert("Sorry, Invalid Credit Card Number."); } }

</script> </head>

<body>

<table width="100%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My WebSite </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11><td background="images/om_top_bg.gif" >

</td></tr>

<tr height=250>

<td background="images/books1.jpg" ></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr><td align="center" colspan="2" valign="top" >

<b><font color="blue">Pay User Registration Fee</font></b>

</td></tr>

<tr><td width='25%' align="right" >User Registration Fee :&nbsp;&nbsp;</td>

<td width='75%' align="left" >5000$</td></tr>

<form name="frm" method="post">

<tr><td width='25%' align="right" >Credit Card Number :&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="ccno" id="ccno" type="text" value="" ><font color='red'>&nbsp;*</font>

<b>Format - XXXX.XXXX.XXXX.XXXX </b> (X -> denotes a number)</td></tr>

</form>

<tr>

<td height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>

<td align="right"> <input name="button" type="button" onClick="javascript:Validate();" value="Save" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:50;height:22" align="absmiddle"/>

&nbsp;&nbsp;.</td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0">

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr> </table> </body> </html>

OUTPUT

USER REGISTRATION

CREDIT CARD PAYMENT

RESULT: Thus the program has been executed and completed successfully.

Ex-No: 3

Title : PROGRAM WHICH TAKES USER ID as INPUT and RETURNS USER

DETAILS

Aim:

To create and save an XML document at the server, which contains 10 users information. Write a program, which takes User Id as an input and returns the user details by taking the user information from the XML document.

XML DOCUMENT

<?xml version="1.0" encoding="ISO-8859-1" ?> - <USERS>- <USER>  <USERID>1001</USERID>   <UNAME>Darani</UNAME>   <UADDRESS>mugappair</UADDRESS>   <UCITY>CHENNAI</UCITY>   <USTATE>TN</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>6000037</UPINCODE>   <UTYPE>lifetime member</UTYPE>   </USER>- <USER>  <USERID>1002</USERID>   <UNAME>lakshman</UNAME>   <UADDRESS>porur</UADDRESS>   <UCITY>CHENNAI</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>600120</UPINCODE>   <UTYPE>member</UTYPE>   </USER>- <USER>  <USERID>1003</USERID>   <UNAME>thiru</UNAME>   <UADDRESS>sulai</UADDRESS>   <UCITY>CHENNAI</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>600023</UPINCODE>   <UTYPE>premium member</UTYPE>

  </USER>- <USER>  <USERID>1004</USERID>   <UNAME>ashok</UNAME>   <UADDRESS>north st</UADDRESS>   <UCITY>thindivanam</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>600045</UPINCODE>   <UTYPE>member</UTYPE>   </USER>- <USER>  <USERID>1005</USERID>   <UNAME>selva</UNAME>   <UADDRESS>mada st</UADDRESS>   <UCITY>villupuram</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>600125</UPINCODE>   <UTYPE>premium member</UTYPE>   </USER>- <USER>  <USERID>1006</USERID>   <UNAME>rama</UNAME>   <UADDRESS>anna nagar</UADDRESS>   <UCITY>CHENNAI</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>602150</UPINCODE>   <UTYPE>lifetime member</UTYPE>   </USER>- <USER>  <USERID>1007</USERID>   <UNAME>prema</UNAME>   <UADDRESS>villivakkam</UADDRESS>   <UCITY>chennai</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>601234</UPINCODE>   <UTYPE>member</UTYPE>   </USER>- <USER>  <USERID>1008</USERID>   <UNAME>sharanya</UNAME>   <UADDRESS>adyar</UADDRESS>   <UCITY>chennai</UCITY>

  <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>602315</UPINCODE>   <UTYPE>lifetime member</UTYPE>   </USER>- <USER>  <USERID>1009</USERID>   <UNAME>jerald</UNAME>   <UADDRESS>1st st</UADDRESS>   <UCITY>theni</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>623511</UPINCODE>   <UTYPE>member</UTYPE>   </USER>- <USER>  <USERID>1010</USERID>   <UNAME>jeena</UNAME>   <UADDRESS>main road</UADDRESS>   <UCITY>nagerkoil</UCITY>   <USTATE>tn</USTATE>   <UCOUNTRY>in</UCOUNTRY>   <UPINCODE>623510</UPINCODE>   <UTYPE>premium member</UTYPE>   </USER>  </USERS>

HTML DOCUMENT

<html>

<head>

<title>My Web Site - User Details</title>

<script language="JavaScript" type="text/JavaScript">

function Validate()

{

if (window.XMLHttpRequest)

{

xhttp=new XMLHttpRequest();

}

else // Internet Explorer 5/6

{

xhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xhttp.open("GET","USER.xml",false);

xhttp.send("");

xmlDoc=xhttp.responseXML;

var rec_found=false;

var x=xmlDoc.getElementsByTagName("USER");

for (i=0;i<x.length;i++)

{

if(frm.muserid.value==x[i].getElementsByTagName("USERID")[0].childNodes[0].nodeValue)

{

frm.uname.value = x[i].getElementsByTagName("UNAME")[0].childNodes[0].nodeValue;

frm.maddress.value = x[i].getElementsByTagName("UADDRESS")[0].childNodes[0].nodeValue;

frm.mcity.value = x[i].getElementsByTagName("UCITY")[0].childNodes[0].nodeValue;

frm.mstate.value = x[i].getElementsByTagName("USTATE")[0].childNodes[0].nodeValue;

frm.mcountry.value = x[i].getElementsByTagName("UCOUNTRY")[0].childNodes[0].nodeValue;

frm.mpincode.value = x[i].getElementsByTagName("UPINCODE")[0].childNodes[0].nodeValue;

frm.musertype.value = x[i].getElementsByTagName("UTYPE")[0].childNodes[0].nodeValue;

rec_found=true;

i=x.length;

}

}

if(rec_found==false)

{

frm.uname.value = "";

frm.maddress.value ="";

frm.mcity.value = "";

frm.mstate.value = "";

frm.mcountry.value = "";

frm.mpincode.value = "";

frm.musertype.value = "";

alert("record not found.");

}

}

</script>

</head>

<body>

<table width="102%" cellpadding="0" cellspacing="0" border="0" >

<tr><td>

<td background="images/inner_part2_bg.jpg" height='103' align='center'>Welcome to My WebSite </span></td></tr>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr height=11><td background="images/om_top_bg.gif" >

</td></tr>

<tr height=11>

<td ><img src="images/CONTACT.jpg"></td></tr>

</table>

<table width="102%" cellpadding="0" cellspacing="0" border="0" background="images/om_bg_panel_blue.gif">

<tr><td align="center" colspan="2" valign="top" >

<b><font color="blue">User Details</font></b>

</td></tr>

<form name="frm" method="post">

<tr><td width='25%' align="right" >User ID :&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="muserid" id="muserid" type="text" value="" ><font color='red'>&nbsp;*</font>

<input name="button" type="button" onClick="javascript:Validate();" value="Get Info" style="border-top:none;border-bottom:none;border-left:none;border-right:none;width:50;height:22"/>

</td></tr>

<tr><td width='25%' align="right" >User Name :&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="uname" id="uname" type="text" value="" ></td></tr>

<tr> <td width='25%' align="right" > Address:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="maddress" id="maddress" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > City:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mcity" id="mcity" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > State:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mstate" id="mstate" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Country:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mcountry" id="mcountry" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > Zip/Pin code:&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="mpincode" id="mpincode" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

<tr> <td width='25%' align="right" > User Type&nbsp;&nbsp;</td>

<td width='75%' align="left"><input name="musertype" id="musertype" type="text" value="" ><font color='red'>&nbsp;*</font>

</td> </tr>

</form>

<tr>

<td colspan='2' height="*" align="left" valign="bottom" ><a href="homepage.html">Home</a>&nbsp;&nbsp;.</td></tr>

</table>

<table width="102%" cellpadding="0" cellspacing="0" border="0">

<tr height=11>

<td background="images/om_top_bg.gif" >

</td></tr>

</table> </body> </html>

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No : 4(a)

Title : CONVERTING THE INR TO THE EQUIVALENT DOLLAR VALUE

Aim:

To create a Java Bean which gives the exchange value of INR (Indian Rupees) into equivalent American/Canadian/Australian Dollar value.

import java.awt.*;

import java.awt.event.*;

public class Convert extends Frame implements ActionListener

{

TextField t1,t2;

Label a1,a2,a3,a4;

List l1;

Button b1;

public Convert()

{

super("Currency Converter");

setBounds(50,50,300,400);

setLayout(null);

t1 = new TextField();

t2 = new TextField();

a1=new Label("Convert to Rupee");

a2=new Label("From Currency");

a3=new Label("Rupee Value");

a4=new Label("Currency Value");

l1=new List(1,false);

l1.add("Dollar");

l1.add("Euro");

l1.add("Pound");

l1.add("Yen");

b1 = new Button("Convert");

a1.setBounds(70,50,100,20);

a4.setBounds(10,120,100,20);

t1.setBounds(150,120,100,20);

a2.setBounds(10,190,100,20);

l1.setBounds(150,190,100,20);

a3.setBounds(10,250,100,20);

t2.setBounds(150,250,100,20);

b1.setBounds(150,350,100,20);

b1.addActionListener(this);

add(a1);

add(a4);

add(t1);

add(a2);

add(l1);

add(a3);

add(t2);

add(b1);

setVisible(true);

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource() == b1)

{

double originalValue=Double.parseDouble(t1.getText());

double rate=0.0;

double convertValue=1.0;

int mIndex=l1.getSelectedIndex();

switch (mIndex){

case 0:

rate=50;

break;

case 1:

rate=57;

break;

case 2:

rate=68;

break;

case 3:

rate=0.5;

break;

}

convertValue=originalValue*rate;

t2.setText(Double.toString(convertValue));

}

}

public static void main(String argv[])

{ Convert c = new Convert(); }

}

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No :4(b)

Title : COUNTER BEAN

Aim:

To create a simple Bean with a label - which is the count of number of clicks. Than create a Bean Info class such that only the “count” property is visible in the Property Window.

import java.awt.*;

public class Counter extends Panel {

  private long count=0;

  private Label label;

  private long maxValue=20;

  public void setMaxValue(long max) {

        maxValue = max;

  }

  public long getMaxValue() { return maxValue; }

   public Counter() {

         setBackground(Color.blue);

         setForeground(Color.white);

         label = new Label(""+count);

         add(label);   }

    public void increment () {

      if (count < maxValue) {

          count++;

          label.setText(count+" ");

      }

      else label.setText("!!");

    }

}

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No :4(c)

Title : CALCULATOR BEAN

Aim:

To create two Beans-a) Key Pad .b) Display Pad. After that integrate the two Beans to make it work as a Calculator.

import java.awt.*;

import java.awt.event.*;

class Calculator extends Frame implements ActionListener

{

TextField t1,t2;

Label l1;

Button b1,b2,b3,b4,b5,b6;

Calculator()

{ super("Calculator");

setBounds(50,50,300,200);

setLayout(null);

t1 = new TextField();

t2 = new TextField();

l1 = new Label();

b1 = new Button("Add");

b2 = new Button("Subtract");

b3 = new Button("Multiply");

b4 = new Button("Divide");

b5 = new Button("Clear");

b6 = new Button("Exit");

t1.setBounds(50,50,50,20);

t2.setBounds(120,50,50,20);

l1.setBounds(190,50,50,20);

b1.setBounds(50,90,50,20);

b2.setBounds(120,90,50,20);

b3.setBounds(190,90,50,20);

b4.setBounds(50,130,50,20);

b5.setBounds(120,130,50,20);

b6.setBounds(190,130,50,20);

l1.setBackground(Color.blue);

l1.setForeground(Color.cyan);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

b6.addActionListener(this);

add(t1);

add(t2);

add(l1);

add(b1);

add(b2);

add(b3);

add(b4);

add(b5);

add(b6);

show();

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource() == b1)

{

int a = Integer.parseInt(t1.getText());

int b = Integer.parseInt(t2.getText());

int c = a+b;

l1.setText(String.valueOf(c));

}

else

if (e.getSource() == b2)

{

int a = Integer.parseInt(t1.getText());

int b = Integer.parseInt(t2.getText());

int c = a-b;

l1.setText(String.valueOf(c));

}

else

if (e.getSource() == b3)

{

int a = Integer.parseInt(t1.getText());

int b = Integer.parseInt(t2.getText());

int c = a*b;

l1.setText(String.valueOf(c));

}

else

if (e.getSource() == b4)

{

int a = Integer.parseInt(t1.getText());

int b = Integer.parseInt(t2.getText());

int c = a/b;

l1.setText(String.valueOf(c));

}

else

if (e.getSource() == b5)

{

t1.setText("");

t2.setText("");

l1.setText("");

t1.requestFocus();

}

else

if (e.getSource() == b6)

System.exit(0);

}

public static void main(String argv[])

{

Calculator o = new Calculator();

}

}

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No: 4(d)

Title : TRAFFIC LIGHT

Aim:

To Create two Beans Traffic Light (Implemented as a Label with only three background colors-Red, Green, Yellow) and Automobile (Implemented as a Text Box which states its state/movement). The state of the Automobile should depend on the following Light Transition Table. Light Transition Automobile

StateRed ---> Yellow ReadyYellow ---> Green MoveGreen --> Red Stopped

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.beans.IntrospectionException;

import java.beans.PropertyDescriptor;

import java.beans.PropertyEditorSupport;

import java.beans.SimpleBeanInfo;

import java.util.TooManyListenersException;

import java.util.Vector;

import javax.swing.JComponent;

public class TrafficLight extends JComponent {

public static String STATE_RED = "RED";

public static String STATE_YELLOW = "YELLOW";

public static String STATE_GREEN = "GREEN";

private static int DELAY = 3000;

private String defaultLightState;

private String currentLightState;

private boolean debug;

private Thread runner;

private transient ActionListener listener;

public TrafficLight() {

defaultLightState = currentLightState = STATE_RED;

setPreferredSize(new Dimension(100, 200));

}

public void paintComponent(Graphics g) {

super.paintComponent(g);

// Paint the outline of the traffic light

g.setColor(Color.white);

g.fillRect(2, 2, 96, 196);

// Debug

if (debug) {

System.out.println("Current light state is: " + currentLightState);

}

// Which light is on?

if (currentLightState.equals(STATE_RED)) {

g.setColor(Color.red);

g.fillOval(30, 30, 40, 40);

} else if (currentLightState.equals(STATE_YELLOW)) {

g.setColor(Color.yellow);

g.fillOval(30, 80, 40, 40);

} else if (currentLightState.equals(STATE_GREEN)) {

g.setColor(Color.green);

g.fillOval(30, 130, 40, 40);

} }

public String getCurrentLightState() {

return currentLightState; }

public void setCurrentLightState(String currentLightState) {

this.currentLightState = currentLightState;

if (currentLightState != STATE_YELLOW) {

if (debug) {

System.out.println("Firing action event");

}

ActionEvent ae = new ActionEvent(this,

ActionEvent.ACTION_PERFORMED, currentLightState);

fireActionPerformed(ae);

}

repaint();

}

public void setDefaultLightState(String defaultLightState) {

this.defaultLightState = defaultLightState;

currentLightState = defaultLightState;

repaint();

}

public String getDefaultLightState() {

return defaultLightState;

}

public void setDebug(boolean debug) {

this.debug = debug;

}

public boolean isDebug() {

return debug; }

public void initiate() {

if (debug) {

System.out.println("Initiate traffic light cycle!");

}

startCycle();

}

private void startCycle() {

if (runner == null) {

Runnable runnable = new Runnable() {

public void run() {

if (debug) {

System.out.println("Started cycle");

}

while (runner != null) {

try {

Thread.sleep(DELAY);

} catch (InterruptedException e) {

}

if (currentLightState.equals(STATE_RED)) {

setCurrentLightState(STATE_GREEN);

} else if (currentLightState.equals(STATE_GREEN)) {

setCurrentLightState(STATE_YELLOW);

} else {

setCurrentLightState(STATE_RED);

}

if (currentLightState.equals(defaultLightState)) {

runner = null;

}

}

}

};

runner = new Thread(runnable);

runner.start();

} }

public void lightChange(ActionEvent x) {

String command = x.getActionCommand();

if (debug) {

System.out.println("Received event from traffic light: "

+ defaultLightState + " command: go to " + command);

}

if (command.equals(STATE_RED)) {

if (!currentLightState.equals(STATE_GREEN)) {

currentLightState = STATE_GREEN;

repaint();

}

} else if (command.equals(STATE_GREEN)) {

if (!currentLightState.equals(STATE_RED)) {

currentLightState = STATE_YELLOW;

repaint();

try {

Thread.sleep(DELAY);

} catch (InterruptedException e) {

}

currentLightState = STATE_RED;

repaint();

} } }

public synchronized void removeActionListener(ActionListener l) {

if (debug) {

System.out.println("Deregistering listener");

}

if (listener == l) {

listener = null;

} }

public synchronized void addActionListener(ActionListener l)

throws TooManyListenersException {

if (debug) {

System.out.println("Registering listener");

}

if (listener == null) {

listener = l;

} else {

throw new TooManyListenersException();

} }

protected void fireActionPerformed(ActionEvent e) {

if (debug) {

System.out.println("Firing action event");

}

if (listener != null) {

listener.actionPerformed(e);

}

}

}

class LightColorEditor extends PropertyEditorSupport {

public String[] getTags() {

String values[] = { TrafficLight.STATE_RED, TrafficLight.STATE_YELLOW,

TrafficLight.STATE_GREEN };

return values;

}

}

class TrafficLightBeanInfo extends SimpleBeanInfo {

public PropertyDescriptor[] getPropertyDescriptors() {

try {

PropertyDescriptor pd1 = new PropertyDescriptor("debug",

TrafficLight.class);

PropertyDescriptor pd2 = new PropertyDescriptor(

"defaultLightState", TrafficLight.class);

pd2.setPropertyEditorClass(LightColorEditor.class);

PropertyDescriptor result[] = { pd1, pd2 };

return result;

} catch (IntrospectionException e) {

System.err.println("Unexpected exception: " + e);

return null;

}

}

}

class MyBean {

private transient Vector actionListeners;

public synchronized void removeActionListener(ActionListener l) {

if (actionListeners != null && actionListeners.contains(l)) {

Vector v = (Vector) actionListeners.clone();

v.removeElement(l);

actionListeners = v;

}

}

public synchronized void addActionListener(ActionListener l) {

Vector v = (actionListeners == null) ? new Vector(2)

: (Vector) actionListeners.clone();

if (!v.contains(l)) {

v.addElement(l);

actionListeners = v;

}

}

protected void fireActionPerformed(ActionEvent e) {

if (actionListeners != null) {

Vector listeners = actionListeners;

int count = listeners.size();

for (int i = 0; i < count; i++) {

((ActionListener) listeners.elementAt(i)).actionPerformed(e);

}

}

}

}

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No: 5

Title : Servlets and Cookies

Aim:

To Install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic web pages using servlets and cookies. Hint: Users information (user id, password, credit card number) would be stored in web.xml. Each user should have a separate Shopping Cart.

LOGIN

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class login extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html><head>");

out.println("<title>Sign In</title>");

out.println("</head><body>");

out.println("<form method=post name=form1 action=http://localhost:8084/WebApplication23/logincheck>");

out.println("<table>");

out.println("<tbody><tr>");

out.println("<td colspan=2><h3>&nbsp;&nbsp;User Login<h3></td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td align=right><b>&nbsp;&nbsp;<label for=email>User Name: </label></b></td>");

out.println("<td >");

out.println("<input id=user name=user type=text>");

out.println("</td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td align=right>&nbsp;&nbsp;<b><label for=returningCust>Password:</label></b></td>");

out.println("<td >");

out.println("<input title=My password is name=password type=password>");

out.println("</td></tr>");

out.println("<tr>");

out.println("<td></td>");

out.println("<td><input type=submit value=submit></td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td colspan=2>");

out.println("<a href=http://localhost:8084/WebApplication19/reg1>New User Click here for Registration</a>");

out.println("</td></tr></tbody>");

out.println("</table>");

out.println("</form>");

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

/* TODO output your page here

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet login</title>");

out.println("</head>");

out.println("<body>");

out.println("<h1>Servlet login at " + request.getContextPath () + "</h1>");

out.println("</body>");

out.println("</html>");

*/

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

LOGIN CKECK

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

public class logincheck extends HttpServlet

{

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();

out.println("<html><head><title>Welcome Page </title>");

out.println("<body>");

out.println("<form method=post action=http://localhost:8084/WebApplication18/login>");

out.println("<div align=right>");

int user_id_count=0;

String user = request.getParameter("user");

String password= request.getParameter("password");

if((user.equals("user")==true)&&(password.equals("password")==true))

{

out.println("<center><b>Welcome User<br><br></center>");

out.println("<center><a href=http://localhost:8084/WebApplication20/profile><b>Update Your Profile</a></center><br><br>");

out.println("<center><a href=http://localhost:8084/WebApplication29/registrationfee><b>Pay The Registration Fee</a></center>");

}

else

{

out.println("<form>");

out.println("<p><p align=left>");

out.println("Sorry you have entered Invalid email or password");

out.println("<p><p align=left>");

out.println("Please check your login or password");

out.println("<Center><input type=submit value=Back></Center></form>");

}

out.println("</form>");

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

/* TODO output your page here

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet logincheck</title>");

out.println("</head>");

out.println("<body>");

out.println("<h1>Servlet logincheck at " + request.getContextPath () + "</h1>");

out.println("</body>");

out.println("</html>");

*/

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

PROFILE PAGE

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class profile extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html><head><title>User Profile Page</title></head><body>");

out.println("<form method=post action=http://localhost:8084/WebApplication18/login>");

out.println(" <table border=0> <tbody><tr><td colspan=2><h3>Share more about yourself</h3></td></tr>");

out.println("<tr><td colspan=2><b>Personal details</b></td></tr>");

out.println("<tbody><tr><td width=1>Location&nbsp;</td><td><input id=rcanLocation name=rcanLocation class=liquid maxlength=100 type=text>");

out.println("<input id=rcanName name=rcanName type=hidden></td><td valign=top><span id=error_number_rcanLocation >&nbsp;</span></td></tr><tr><td >Birthday&nbsp;</td>");

out.println("<td><div id=div_pdpBirthDay>");

out.println(" <select id=_po_pdpBirthDayMonth name=_po_pdpBirthDayMonth class=>");

out.println("<option value=0 selected=selected>Month</option>");

out.println("<option value=1>January</option>");

out.println("<option value=2>February</option>");

out.println("<option value=3>March</option><option value=4>April</option>");

out.println("<option value=5>May</option><option value=6>June</option>");

out.println("<option value=7>July</option><option value=8>August</option>");

out.println("<option value=9>September</option><option value=10>October</option>");

out.println("<option value=11>November</option><option value=12>December</option>");

out.println("</select>");

out.println("<select id=_po_pdpBirthDayDay name=_po_pdpBirthDayDay >");

out.println("<option value=0 selected=selected>Day</option><option value=1>1</option> <option value=2>2</option><option value=3>3</option><option value=4>4</option>");

out.println("<option value=5>5</option><option value=6>6</option><option value=7>7</option>");

out.println("<option value=8>8</option><option value=9>9</option><option value=10>10</option>");

out.println("<option value=11>11</option><option value=12>12</option>");

out.println("<option value=13>13</option><option value=14>14</option><option value=15>15</option>");

out.println("<option value=16>16</option><option value=17>17</option><option value=18>18</option>");

out.println("<option value=19>19</option><option value=20>20</option><option value=21>21</option>");

out.println("<option value=22>22</option><option value=23>23</option><option value=24>24</option>");

out.println("<option value=25>25</option><option value=26>26</option><option value=27>27</option>");

out.println("<option value=28>28</option><option value=29>29</option><option value=30>30</option>");

out.println("<option value=31>31</option>");

out.println("</select>");

out.println("<span id=error_number_pdpBirthDay >&nbsp;</span>");

out.println("</div></td>");

out.println("<td></td></tr>");

out.println("<tr><td class=nowrap>Anniversary&nbsp;</td><td><div id=div_pdpAnniversary>");

out.println("<select id=_po_pdpAnniversaryMonth name=_po_pdpAnniversaryMonth>");

out.println("<option value=0 selected=selected>Month</option>");

out.println("<option value=1>January</option> <option value=2>February</option><option value=3>March</option> <option value=4>April</option>");

out.println("<option value=5>May</option><option value=6>June</option><option value=7>July</option> <option value=8>August</option>");

out.println("<option value=9>September</option><option value=10>October</option><option value=11>November</option> <option value=12>December</option>");

out.println("</select>");

out.println("<select gtbfieldid=20 id=_po_pdpAnniversaryDay name=_po_pdpAnniversaryDay >");

out.println("<option value=0 selected=selected>Day</option><option value=1>1</option>");

out.println("<option value=2>2</option>");

out.println("<option value=3>3</option> <option value=4>4</option><option value=5>5</option>");

out.println("<option value=6>6</option><option value=7>7</option><option value=8>8</option>");

out.println("<option value=9>9</option><option value=10>10</option> <option value=11>11</option>");

out.println("<option value=12>12</option><option value=13>13</option><option value=14>14</option>");

out.println(" <option value=15>15</option><option value=16>16</option><option value=17>17</option>");

out.println("<option value=18>18</option><option value=19>19</option><option value=20>20</option>");

out.println("<option value=21>21</option><option value=22>22</option><option value=23>23</option>");

out.println("<option value=24>24</option><option value=25>25</option><option value=26>26</option>");

out.println("<option value=27>27</option><option value=28>28</option><option value=29>29</option>");

out.println("<option value=30>30</option><option value=31>31</option>");

out.println("</select>");

out.println("</div></td>");

out.println("<td></td></tr>");

out.println("<tr><td >Web page&nbsp;</td><td><input id=pdpWebsite name=pdpWebsite maxlength=100 type=text>");

out.println("</td></tr>");

out.println("<tr><td valign=top>E-mail&nbsp;</td><td><input id=pdpPublicEmail name=pdpPublicEmail maxlength=100 type=text>");

out.println("</div></td></tr><tr><td valign=top><div>Select photo</div></td><td>");

out.println("<input id=file_1 name=file_1 type=file></td></tr><tr><td valign=top><div>Add a caption</div></td>");

out.println("<td><input id=caption_1 name=caption_1 size=40 type=text>");

out.println("</td></tr>");

out.println("<tr><td>Describe Yourself</td><td><textarea id=pdpPersonalDescription name=pdpPersonalDescription rows=3></textarea></td> </tr>");

out.println("<tr><td><input type=submit value=finish border=0 height=22 width=75></td> </tr>");

out.println("</tbody></table></body></html>");

//out.println("entered all the details successfully");

/* TODO output your page here

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet profile</title>");

out.println("</head>");

out.println("<body>");

out.println("<h1>Servlet profile at " + request.getContextPath () + "</h1>");

out.println("</body>");

out.println("</html>");

*/

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

REGISTRATION

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class reg1 extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html><head>");

out.println("<title>Registration Page</title>");

out.println("</head><body>");

out.println("<form method=post action=http://localhost:8084/WebApplication21/usereg>");

out.println(" <table border=0>");

out.println("<tbody><tr>");

out.println("<td colspan=2><h3 >New User? Register Below.</h3></td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td align=right><b>My name is:</b></td>");

out.println("<td><input name=userName size=30 maxlength=50></td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td align=right><b>My e-mail address:</b></td>");

out.println("<td><input name=email size=30 maxlength=64 type=text></td>");

out.println("</tr>");

out.println("<tr>");

out.println("<td align=right><b>Type it again:</b></td>");

out.println("<td><input name=emailCheck size=30 maxlength=64 type=text></td></tr>");

out.println("<tr>");

out.println("<td align=right><b>Birthday:</b></td>");

out.println("<td>");

out.println("<select name=month>");

out.println("<option selected=selected>Month</option>");

out.println("<option value=1>");

out.println("January");

out.println("</option>");

out.println("<option value=2>");

out.println("February");

out.println("</option>");

out.println("<option value=3>");

out.println("March");

out.println("</option>");

out.println("<option value=4>");

out.println("April");

out.println("</option>");

out.println("<option value=5>");

out.println("May");

out.println("</option>");

out.println("<option value=6>June</option>");

out.println("<option value=7>July</option>");

out.println("<option value=8>August</option>");

out.println("<option value=9>September</option>");

out.println("<option value=10>October</option>");

out.println("<option value=11>November</option>");

out.println("<option value=12>December</option>");

out.println("</select>");

out.println("<select name=day> <option selected=selected >Day</option>");

out.println("<option value=1>01</option>");

out.println("<option value=2>02</option> <option value=3>03</option>");

out.println("<option value=4>04</option><option value=5>05</option>");

out.println("<option value=6>06</option><option value=7>07</option>");

out.println("<option value=8>08</option>");

out.println("<option value=9>09</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>");

out.println("<option value=16>16</option><option value=17>17</option><option value=18>18</option><option value=19>19</option>");

out.println("<option value=20>20</option><option value=21>21</option><option value=22>22</option><option value=23>23</option>");

out.println("<option value=24>24</option><option value=25>25</option><option value=26>26</option><option value=27>27</option>");

out.println("<option value=28>28</option><option value=29>29</option><option value=30>30</option><option value=31>31</option>");

out.println("</select>");

out.println("<b>(optional)</b>");

out.println("</td></tr>");

out.println("<tr> <td align=right><b>Enter a new password:</b></td><td><input name=password type=password></td></tr>");

out.println("<tr> <td align=right><b>Type it again:</b></td> <td><input name=passwordCheck type=password></td></tr>");

out.println("<tr></tr><tr><td>&nbsp;</td><td><input type=submit value=login ></td> </tr>");

out.println("</tbody>");

out.println("</table>");

out.println("</form></body></html>");

/* TODO output your page here

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet reg1</title>");

out.println("</head>");

out.println("<body>");

out.println("<h1>Servlet reg1 at " + request.getContextPath () + "</h1>");

out.println("</body>");

out.println("</html>");

*/

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

REGISTRATION FEE

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class registrationfee extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<HTML><HEAD><TITLE>My Web Site - Pay User Registration Fee</TITLE>");

/*<SCRIPT language=JavaScript type=text/JavaScript>

function Validate()

{

var errflag=false;

var numlength=0;

var usrstr=frm.ccno.value;

var strlength=usrstr.length;

if (strlength==19)

{

for(i=0;i<usrstr.length;i++)

{

if (i==4 || i==9 || i==14)

{

if(usrstr.charCodeAt(i)==46)

numlength++;

}

else

{

if(usrstr.charCodeAt(i)>47 && usrstr.charCodeAt(i)<58)

numlength++;

}

}

if(numlength==19)

{

alert("Credit Card Payment Sucessfully Completed.");

frm.action="userpage.html";

frm.submit();

}

else

{

alert("Sorry, Invalid Credit Card Number.");

}

}

else

{

alert("Sorry, Invalid Credit Card Number.");

}

}

</SCRIPT>

*/

out.println("<BODY>");

out.println("<center><b>Welcome to My WebSite</center>");

out.println("<b><FONT color=blue><center><b>Pay User Registration Fee</center></FONT></B></br>");

out.println("<b>User Registration Fees:");

out.println("<b>100$");

out.println("<FORM method=post action=http://localhost:8084/WebApplication20/profile>");

out.println("Credit Card Number");

out.println("<INPUT id=ccno name=ccno><FONT olor=red>&nbsp;*</FONT>");

out.println("<B>Format - XXXX.XXXX.XXXX.XXXX</B> (X -&gt;denotes a number)<br>");

out.println("<center><A href=http://localhost:8084/WebApplication18/login>Home<br></A><center></br>");

out.println("<input type=submit value=save>");

out.println("</BODY></HTML>");

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

USER PAGE

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

public class userpage extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();

out.println("<html>");

out.println("<head>");

out.println("<title>Home Page");

out.println("</title>");

out.println("<style type=text/css>");

out.println("</style>");

out.println("</head>");

out.println("<body >");

out.println("<table border=0 width=100>");

out.println("<tr><td align=right>");

if (session.getAttribute("email") != null)

{

out.println("<font size=3>Welcome");

session.getAttribute("email");

out.println("</font><br>");

out.println("<a href=http://localhost:8084/WebApplication20/profile> onClick=session.invalidate() log out</a>");

}

else

{

out.println("<a href=http://localhost:8084/WebApplication18/login>login</a>");

}

/*out.println("</td></tr>");

out.println("<tr><td align=left><font color=Black size=5>Books Catalog </font><hr></td></tr>");

out.println("<tr><td>");

out.println("<tr >");

out.println("<td >");

out.println("<font color='#900299' size=4>");

res.getString("title");

out.println("</font><br>");

out.println("<font size=3>Description:<b>");

res.getString("description");

out.println("</font></b><br>Author:");

out.println("<font size=3><b>");

res.getString("author");

out.println("</font></b><br>Publication:");

out.println("<font size=3><b>");

res.getString("publication");

out.println("</font></b><br>Price:");

out.println("<font size=3><b>");

out.println(rs.getString("price") + " INR");

out.println("</font></b><br>");

out.println("<hr>");

out.println("</td>");

out.println("</tr>");

out.println("</td></tr></table>");*/

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

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

USER REGISTRATION

import java.io.*;

import java.net.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class usereg extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

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

String email=request.getParameter("email");

String emailCheck= request.getParameter("emailCheck");

String month = request.getParameter("month");

String day= request.getParameter("day");

String password= request.getParameter("password");

String passwordCheck= request.getParameter("passwordCheck");

out.println("<html>");

out.println("<body >");

out.println("<Script language=JavaScript>");

out.println("function next()");

out.println("{");

out.println("window.history.location(login.java)");

out.println("}");

out.println("</Script>");

out.println("<form><p > </p>");

out.println("<font color=black ><p align=left>You Have Successfully Registered.. <a href=http://localhost:8084/WebApplication18/login>Click here to Login</a>");

out.println("<Center>");

out.println("</Center></font></form>");

out.println("</body>");

out.println("</html>");

/* TODO output your page here

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet usereg</title>");

out.println("</head>");

out.println("<body>");

out.println("<h1>Servlet usereg at " + request.getContextPath () + "</h1>");

out.println("</body>");

out.println("</html>");

*/

out.close();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

public String getServletInfo() {

return "Short description";

}

}

Output

RESULT:

Thus the program has been executed and completed successfully.

Ex-No: 6

Title : CONVERTING STATIC PAGE TO DYNAMIC PAGE USING JSP

Aim:

To Redo the previous task using JSP by converting the static web pages of assignments 2 into dynamic web pages. Create a database with user information and books information. The books catalogue should be dynamically loaded from the database. Follow the MVC architecture while doing the website.

LOGIN.JSP

<html><head>

<title>Sign In</title>

</head><body>

<form method="post" name="form1" action="logincheck.jsp">

<table >

<tbody><tr>

<td colspan="2"><h3>&nbsp;&nbsp;User Login<h3></td>

</tr>

<tr>

<td align="right"><b>&nbsp;&nbsp;<label for="email">E-mail address: </label></b></td>

<td >

<input id="email" name="email" size="30" maxlength="64"

type="text"></td>

</tr>

<tr>

<td align="right">&nbsp;&nbsp;<b><label for="returningCust">Password:</label></b></td>

<td >

<input title="My password is" name="password" size="10" maxlength="1024" type="password">

</td></tr>

<tr>

<td>&nbsp;</td>

<td><input src="images/s.bmp" type="image" id="submit" border="0" height="22" width="84"></td>

</tr>

<tr>

<td colspan="2" >

<a href="reg1.jsp">New User Click here for Registration</a>

</td></tr></tbody>

</table>

</form>

</body></html>

LOGIN CHECK.JSP

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

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

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

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

<html>

<head>

<title>Welcome Page </title>

<Script language="JavaScript">

function next()

{

window.history.back();

}

</Script>

<style type="text/css">

<!--

a:visited {

color: #990099;

}

a:link {

color: #0000FF;

}

.style2 {

font-family: "Book Antiqua";

font-style: italic;

font-weight: bold;

color: #6699FF;

}

.style3 {

color: #660000;

font-style: italic;

font-weight: bold;

}

-->

</style>

<body>

<form name="form1" method=post >

<div align="right">

<%

int user_id_count=0;

String s3;

String connectionURL = "jdbc:odbc:dsnshop;user=root;password=laxman";

Connection connection = null;

Statement statement = null;

ResultSet rs = null;

String email = request.getParameter("email");

String password= request.getParameter("password");

%>

<%

try

{

Connection conn = DriverManager.getConnection(connectionURL);

statement = conn.createStatement();

s3="select email,password FROM tbl_user where email='"+ email +"' and password='"+ password +"';";

rs=statement.executeQuery(s3);

while(rs.next())

{

user_id_count=1;

}

rs.close();

statement.close();

conn.close();

}

catch(Exception e)

{

System.out.println("Exception"+e);

}

if(user_id_count==1)

{

session.setAttribute( "email", email );

response.sendRedirect("userpage.jsp");

}

else

{

%>

<form>

<p><p align="left">

Sorry you have entered Invalid email or password.

<p><p align="left">

Please check your login or password.

<p align="left"><p>

<Center>

<input type=button value=Back name=b1 onClick="next();">

</Center></form>

<%}

%>

</form>

</body>

</html>

REG1.JSP

<html><head>

<title>Registration Page</title>

</head><body>

<form method="post" name="form1" action="user_reg.jsp">

<table border="0">

<tbody><tr>

<td colspan="2"><h3 >New User? Register Below.</h3></td>

</tr>

<tr>

<td align="right"><b>My name is:</b></td>

<td><input name="userName" size="30" maxlength="50"></td>

</tr>

<tr>

<td align="right"><b>My e-mail address:</b></td>

<td><input name="email" size="30" maxlength="64"

value="" type="text"></td>

</tr>

<tr>

<td align="right"><b>Type it again:</b></td>

<td><input name="emailCheck" size="30" maxlength="64"

type="text"></td>

</tr>

<tr>

<td align="right"><b>Birthday:</b></td>

<td>

<select name="month">

<option selected="selected" value="">Month</option>

<option value="1">

January

</option>

<option value="2">

February

</option>

<option value="3">

March

</option>

<option value="4">

April

</option>

<option value="5">

May

</option>

<option value="6">

June

</option>

<option value="7">

July

</option>

<option value="8">

August

</option>

<option value="9">

September

</option>

<option value="10">

October

</option>

<option value="11">

November

</option>

<option value="12">

December

</option>

</select>

<select name="day">

<option selected="selected" value="">Day</option>

<option value="1">01</option>

<option value="2">02</option>

<option value="3">03</option>

<option value="4">04</option>

<option value="5">05</option>

<option value="6">06</option>

<option value="7">07</option>

<option value="8">08</option>

<option value="9">09</option>

<option value="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 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>

</select>

<b>(optional)</b>

</td>

</tr>

<tr>

<td align="right"><b>Enter a new password:</b></td>

<td><input name="password" autocomplete="off" maxlength="20"

type="password"></td>

</tr>

<tr>

<td align="right"><b>Type it again:</b></td>

<td><input name="passwordCheck" autocomplete="off" maxlength="20"

type="password"></td>

</tr>

<tr>

</tr>

<tr>

<td>&nbsp;</td>

<td><input src="images/continue-blue-arrow.gif" value="Continue"

type="image" align="absmiddle" border="0" height="22" width="84"></td>

</tr>

</tbody></table>

</form>

</body></html>

USER REG.JSP

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

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

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

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

<%

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

String email=request.getParameter("email");

String emailCheck= request.getParameter("emailCheck");

String month = request.getParameter("month");

String day= request.getParameter("day");

String password= request.getParameter("password");

String passwordCheck= request.getParameter("passwordCheck");

%>

<%

try

{

Connection conn = DriverManager.getConnection("jdbc:odbc:dsnshop;",

"root", "laxman");

PreparedStatement ps=conn.prepareStatement("INSERT INTO tbl_user VALUES (?,?,?,?,?)");

ps.setString(1,username);

ps.setString(2,email);

ps.setString(3,month);

ps.setString(4,day);

ps.setString(5,password);

ps.execute();

conn.close();

}

catch(Exception e)

{

out.println(e);

}

%>

<html>

<body >

<Script language="JavaScript">

function next()

{

window.history.location("login.jsp");

}

</Script>

<form><p > </p>

<font color="black" ><p align="left">You Have Successfully Registered.. <a href="login.jsp">Click here to Login</a>

<Center>

</Center></font></form>

</body>

</html>

USER PAGE.JSP

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

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

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

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

<%

String s3;

String connectionURL = "jdbc:odbc:dsnshop;user=root;password=laxman";

Connection conn = null;

Statement statement = null;

ResultSet rs = null;

%>

<html>

<head>

<title>Home Page

</title>

<script language="javascript">

function cancel()

{

history.back();

}

</script>

<style type="text/css">

</style>

</head>

<body >

<table border=0 width="100%" >

<tr>

<td align="right">

<% if (session.getAttribute("email") != null)

{

%>

<font size=3>Welcome, <%= session.getAttribute("email") %></font><br>

<a href="userpage.jsp" onClick="<% session.invalidate(); %>"

>log out</a>

<% }

else

response.sendRedirect("login.jsp");

%>

</td>

</tr>

<tr>

<td align="left" >

<font color="Black" size=5>Books Catalog </font><hr>

</td></tr>

<tr> <td>

<% try

{

conn = DriverManager.getConnection(connectionURL);

statement = conn.createStatement();

s3="select * FROM tbl_book;";

rs=statement.executeQuery(s3);

out.println("<table border=0 width='100%' >");

while (rs.next()) {

out.println("<tr >");

out.println("<td >");

out.println("<font color='#900299' size=4>");

out.println(rs.getString("title"));

out.println("</font><br>");

out.println("<font size=3>Description:<b>");

out.println(rs.getString("description"));

out.println("</font></b><br>Author:");

out.println("<font size=3><b>");

out.println(rs.getString("author"));

out.println("</font></b><br>Publication:");

out.println("<font size=3><b>");

out.println(rs.getString("publication"));

out.println("</font></b><br>Price:");

out.println("<font size=3><b>");

out.println(rs.getString("price") + " INR");

out.println("</font></b><br>");

out.println("<hr>");

out.println("</td>");

out.println("</tr>");

}

out.println("</table>");

rs.close();

statement.close();

conn.close();

}

catch(Exception e)

{

System.out.println("Exception"+e);

}

%>

</td> </tr> </table> </body>

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.

Ex-No: 7

Title : JSP STRUTS FRAMEWORK

Aim:

To implement the “Hello World!” program using JSP Struts Framework.

INDEX.JSP

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<logic:redirect forward="helloWorld"/>

HELLOWORLD.JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Hello World</title>

</head>

<body>

<bean:write name="helloWorldForm" property="message"/>

</body>

</html>

STRUTS-CONFIG.XML

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

<!DOCTYPE struts-config PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"

"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

<form-beans>

<form-bean name="helloWorldForm" type="com.vaannila.form.HelloWorldForm"/>

</form-beans>

<global-forwards>

<forward name="helloWorld" path="/helloWorld.do"/>

</global-forwards>

<action-mappings>

<action path="/helloWorld" type="com.vaannila.action.HelloWorldAction" name="helloWorldForm">

<forward name="success" path="/helloWorld.jsp" />

</action>

</action-mappings>

</struts-config>

WEB.XML

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

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<display-name>StrutsExample1</display-name>

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-config.xml</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<welcome-file-list>

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

</welcome-file-list>

</web-app>

HELLO WORLD ACTION.JAVA

package com.vaannila.action;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import com.vaannila.form.HelloWorldForm;

public class HelloWorldAction extends Action {

@Override

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

HelloWorldForm hwForm = (HelloWorldForm) form;

hwForm.setMessage("Hello World");

return mapping.findForward("success");

}

}

HELLO WORLD FORM.JAVA

package com.vaannila.form;

import org.apache.struts.action.ActionForm;

public class HelloWorldForm extends ActionForm {

private static final long serialVersionUID = -473562596852452021L;

private String message;

public String getMessage() {

return message; }

public void setMessage(String message) {

this.message = message;

} }

OUTPUT

RESULT:

Thus the program has been executed and completed successfully.