Sie sind auf Seite 1von 61

JAVA & WEB TECHNOLOGIES

1. Develop an ONLINE BOOK STORE application using HTML which consists the books information. The online application consist the following web pages. Home page Registration page User Profile Shopping catalogue Shopping cart Payment by Credit card Order Conformation
Home Page With User Authentication A) Online.html <html> <head><title>Royal</title></head> <frameset rows="110,*" cols="*" frameborder="no" border="1" framespacing="0"> <frame src="Book_top.html" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" /> <frameset rows="*" cols="158,*" framespacing="0" frameborder="no" border="0"> <frame src="Book_left.html" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" /> <frame src="Book.html" name="mainFrame" id="mainFrame"scrolling="yes"/> </frameset> </frameset> </html> B) Book_top.html <html> <head> <title>Royal</title> <style type="text/css"> body { background-image: url(Images/books24x7_smlogo.gif); background-repeat: no-repeat; background-color: #B6DADA; } .style2 {color: #CC6666} a:link { color: #993300; text-decoration: none; } a:visited { text-decoration: none; 1 NIET

JAVA & WEB TECHNOLOGIES color: #FF0000; } a:hover { text-decoration: none; color: #330000; } a:active { text-decoration: none; color: #333399; } .style3 {color: #9E3434; } .table1 td{ text-align :center; } </style> </head> <body> <h1 align="center" class="style3"> Nizam Online Shopping Centre </h1> <center> <strong> <table border="1" class="table1"> <tr> <td width="100"><a href="Login.html" target="mainFrame"> Login</a></td> <td width="120"><a href="Registration.html" target="mainFrame"> Registration</a></td> <td width="120"><a href="Feroz.html" target="mainFrame">Userprofile</a></td> <td width="120"> <a href="Login.html" target="_parent">Logout </a></td> </tr> </table> </body></html> C) Book_left.html <html> <head> <title> Book_left </title> <style type="text/css"> body,td,th { color: #990000; } a:link { color: #990066; text-decoration: none; } a:visited { text-decoration: none; color: #FF3300; } a:hover { text-decoration: none; 2 NIET

JAVA & WEB TECHNOLOGIES color: #003300; } a:active { text-decoration: none; color: #3366CC; } body { background-color: #B6DADA; } </style><title>Left Frame</title></head> <body> <form id="form1" name="form1" method="post" action=""> <br /><br /> Search :<input name="search" type="text" id="search" size="8" /> <br /> </form> <p>Product Catalog : </p> <ul> <li><a href="Mobiles.html" target="mainFrame">Mobiles</a></li> <li><a href="Computers.html" target="mainFrame">Computers</a></li> <li><a href="Book.html" target="mainFrame">Books</a></li> <li><a href="Electronics.html" target="mainFrame">Electronics</a></li> </ul> </body> </html>

D) Book.html
<html> <head> <title>RoyalShopping</title> <style type="text/css"> body { background-color: #99CCCC; } .style4 { font-family: Georgia, "Times New Roman", Times, serif; color: #FFCC33; } </style></head> <body> <p>&nbsp;</p> <p>&nbsp;</p> <div align="center"> <h1 class="style4">&nbsp;</h1> <h1 class="style4">COMPUTERS</h1> </div> <h1>&nbsp;</h1> </body> </html> 3 NIET

JAVA & WEB TECHNOLOGIES E) Login.html <html> <head> <title>Authenticate</title> <style type="text/css"> .style1 { color: #990000; font-style: italic; font-weight: bold; } body { background-color: #A2CAC9; } </style> </head> <body> <p>&nbsp;</p> <p>&nbsp;</p> <p align="center" class="style1">Please Authenticate </p> <table width="261" height="78" border="1" align="center" bgcolor="#408080"> <tr> <th width="114" height="39" scope="col"><div align="center"><strong>User Name </strong></div></th> <th width="101" scope="col"><input type="text" name="textfield" /></th> </tr> <tr> <td height="24"><div align="center"><strong>Password</strong></div></td> <td><input name="password" type="password" id="password" /></td> </tr> </table> <p align="center">&nbsp;</p> <table width="200" border="1" align="center"> <tr> <th bgcolor="#408080" scope="col"><form action="Online.html" method="post" name="form1" target="_self" id="form1"> <input type="submit" name="Submit" value="Submit" /> </form> </th> </tr> </table> </body> </html>

4 NIET

JAVA & WEB TECHNOLOGIES F) Registration.html <html> <head> <title>The Registration Form </title> <style type="text/css"> body { background-color: #408080; } .style1 {color: #FF0000} </style> </head> <body> <p>&nbsp;</p> <h2 align="center" class="style1">The Registration Form </h2> <table width="242" border="1" align="center"> <tr> <th width="92" scope="col">User Name </th> <th width="134" scope="col"><input type="text" name="name" id="name" /></th> </tr> <tr> <td><strong>Password</strong></td> <td><input type="password" id="password" /></td> </tr> <tr> <td><strong>e@mail</strong></td> <td><input type="text" id="email" /></td> </tr> <tr> <td><strong>Mobile</strong></td> <td><input type="text" id="mobile" /></td> </tr> <tr> <td><strong>City</strong></td> <td><input type="text" id="city" /></td> </tr> </table> <p>&nbsp;</p> <table width="200" border="1" align="center"> <tr> <th height="23" scope="col"> <input type="submit" name="Submit" value="Submit" onClick='validate()' /> </th> </tr> </table> <p>&nbsp;</p> </body> </html> 5 NIET

JAVA & WEB TECHNOLOGIES G) Mobiles.html <html> <head> <title>Mobile1</title> <style type="text/css"> body { background-color: #99CCFF; } </style> </head> <body><center> <h1>Mobiles Shopping List</h1><br>All Types of Mobiles are available here....Click for More Information<br> &nbsp;&nbsp;&nbsp;&nbsp; <a href="file:///D:/WebTech-Lab/Mobile1.html"> <img src="file:///D:/WebTech-Lab/Images/Mobile1.jpg"/></a> <a href="www.mobile2.com"><img src="file:///D:/WebTech-Lab/Images/Mobile2.jpg"/></a> <a href="www.mobile3.com"><img src="file:///D:/WebTech-Lab/Images/Mobile3.jpg"/></a> <a href="www.mobile5.com"><img src="file:///D:/WebTech-Lab/Images/Mobile5.jpg" width="80" height="110"/></a> </body> </html> H) Nokia.html <HTML> <HEAD> <TITLE> www.Nokia.com </TITLE> <style> .table1 th { background-color:yellow; } td { text-align :center; } tr{background-color:pink;} </style> </HEAD> <BODY bgcolor="#DCF0F9"><center><h2>Click For More Details .... <table width="100%" height="10%" border="1" class="table1"> <tr><th>Name</th><th>Description</th><th>Price</th><th>Details</th></tr> <tr><td>Nokia 6600</td><td>LG-brand</td><td>4,500</td><td><a href="file:///D:/WebTechLab/Browse.html" target="mainFrame">Details</a></td></tr> <tr><td>Nokia 3230</td><td>Tata</td><td>4,000</td><td><a href="#">Details</a></td></tr> <tr><td>Nokia 1100</td><td>Motorola</td><td>9,500</td><td><a href="#">Details</a></td></tr> <tr><td>Nokia N73</td><td>SamSung</td><td>13,,500</td><td><a href="#">Details</a></td></tr> 6 NIET

JAVA & WEB TECHNOLOGIES </table> </BODY> </HTML> I) Browse.html <HTML> <HEAD> <TITLE> Browse</TITLE> </HEAD> <BODY bgcolor="#DCF0F9"><br>Nokia 6600<br> <center><img src="file:///D:/WebTech-Lab/Images/Mobile1.jpg"/>&nbsp; <a href="file:///D:/WebTech-Lab/AddToCart.html">Add To Cart</a> </BODY> </HTML> J) AddToCart.html <HTML> <HEAD> <TITLE> addToCart</TITLE> <style> th{ background-color :yellow; } td{ background-color :cyan; text-align :center; } </style> </HEAD> <BODY bgcolor="#DCF0F9"><center><h2>Detailes of Your Shopping Cart.... <center><b><table width="100%" border="1"> <tr> <th>Name</th><th>Description</th> <th>Price</th><th>Quantity</th><th>Subtotal</th> </tr> <tr> <td>Nokia 6600</td><td>LG-Product</td><td>4,500</td><td><input type="text" size="3" name="quantity" value="2"/></td><td>9000</td> </tr> </table><br> <table border="1" width="50%"><form action="file:///D:/WebTech-Lab/Checkout.html" method="post"> <tr> <td><input type="submit" value="CheckOut" /></td> <td><input type="submit" value="Update"/></td> <td><input type="submit" value="Delete"/></td> </tr> </table> </form> </BODY> </HTML> 7 NIET

JAVA & WEB TECHNOLOGIES K) Checkout.html <HTML> <HEAD> <TITLE>Checkout </TITLE> </HEAD> <BODY bgcolor="#DCF0F9"> <form action="file:///D:/WebTech-Lab/ Payment.html"> <table width="250" border="1" align="center"> <tr> <td><strong>Contact Name </td> <td><input type="text" name="name" id="name" /></td> </tr> <tr> <td><strong>Address</strong></td> <td><input type="password" id="password" /></td> </tr> <tr> <td><strong>e@mail</strong></td> <td><input type="text" id="email" /></td> </tr> <tr> <td><strong>Mobile</strong></td> <td><input type="text" id="mobile" /></td> </tr> <tr> <td><strong>City</strong></td> <td><input type="text" id="city" /></td> </tr> <tr> <td><strong>Credit Card Type</strong></td> <td><input type="text" id="creditcardtype" /></td> </tr> <tr> <td><strong>Credit Card Number</strong></td> <td><input type="text" id="creditcardnumber" /></td> </tr> </table> <table width="200" border="1" align="center"> <tr> <th height="23" scope="col"> <input type="submit" name="Submit" value="Submit"/> </th> </tr> </table> </BODY>

8 NIET

JAVA & WEB TECHNOLOGIES L) Payment.html <HTML> <HEAD> <TITLE Payment </TITLE> </HEAD> <BODY bgcolor="#DCF0F9"> <CENTER><H2><BR><BR><BR><HR>YOUR DATA HAS BEEN SUCCESSFULLY SAVED..</H2><HR>Thanks For Visiting<HR>

Home Page with Authentication SCREEN

9 NIET

JAVA & WEB TECHNOLOGIES

Registration Screen

Mobiles

10 NIET

JAVA & WEB TECHNOLOGIES

Nokia

Browse

11 NIET

JAVA & WEB TECHNOLOGIES

addToCart

CheckOut-Payment Roll

12 NIET

JAVA & WEB TECHNOLOGIES

2. Write a JavaScript code to validate the user login page registration page, and payment by Credit Card page.
<HTML> <HEAD> <TITLE>Form Validation using javascript </TITLE> <style> td { text-align:center; font-weight:solid; font-family:georgia; } select { background-color:#B0E8EE; width:100%; } input { background-color:#B0E8EE; } </style> <script> function validation() { //alert("validation"); var name=document.getElementById("name").value; var password=document.getElementById("password").value; var confirmPassword=document.getElementById("confirmPassword").value; var mobile=document.getElementById("mobile").value; var email=document.getElementById("email").value; var creditcardno=document.getElementById("creditcardno").value; var lang=document.getElementById("language").checked; var hindi=document.getElementById("hindi").checked; var eng=document.getElementById("english").checked; var state=document.getElementById("state").value; if(name=="") { alert("Fill The Name "); document.getElementById("name").focus(); return false; } else if(password=="") { 13 NIET

JAVA & WEB TECHNOLOGIES alert("Password Should not be blank"); document.getElementById("password").focus(); return false; } else if(confirmPassword=="") { alert("Password Should not be blank"); document.getElementById("confirmPassword").focus(); return false; } else if(password!=confirmPassword) { alert("Password Should be Match"); document.getElementById("confirmPassword").focus(); return false; } else if(isNaN(mobile) || mobile.length < 10) { alert("Number Should be Positive "); document.getElementById("mobile").focus(); return false; } else if(email=="") { alert("Enter The valid E-mail Id "); document.getElementById("email").focus(); return false; } else if(creditcardno=="" || isNaN(creditcardno)) { alert("Enter The valid Credit Card Number "); document.getElementById("creditcardno").focus(); return false; } else if(lang==false) { alert("please select atleast one language"); return false; } else if(state=="SELECT") { alert("please select State"); return false; } else { alert("Redirecting to another page , please wait....."); } 14 NIET

JAVA & WEB TECHNOLOGIES }</script> </HEAD> <BODY bgcolor="#43A9A7"><center><FONT STYLE="TIMESNEWROMAN" SIZE="5" COLOR="red"> <u>Please Fill The Regiatration Form</u></FONT> <br> <table border="1" bgcolor="#DCF7Fk"> <tr><td>Name :</td><td><INPUT TYPE="text" id="name" size="21"/></td></tr> <tr><td>Password :</td><td><INPUT TYPE="password" id="password" size="21"/></td></tr> <tr><td>Confirm Password :</td><td><INPUT TYPE="password" id="confirmPassword" size="21"/></td></tr> <tr><td>Mobile :</td><td><INPUT TYPE="text" id="mobile" size="21"/></td></tr> <tr><td>Email Id :</td><td><INPUT TYPE="text" id="email" size="21"/></td></tr> <tr><td>Credit Card Number :</td><td><INPUT TYPE="text" id="creditcardno" size="21"/></td></tr> <tr><td>Credit Card Type :</td><td><select name="state" id="state" width="35"> <option value="SELECT" selected>SELECT...</option> <option value="visa">Visa Card</option> <option value="master" >Master Card</option> <option value="shopping Card">Standard Card</option></td></tr> </select> <tr><td>Gender :</td><td><INPUT TYPE="radio" id="male" name="gender" checked/>Male &nbsp;&nbsp;&nbsp;<INPUT TYPE="radio" id="female" name="gender"/>Female</td></tr> <tr><td>Languages :</td><td><INPUT TYPE="checkbox" id="hindi" name="language" />Hindi &nbsp;&nbsp;&nbsp;<INPUT TYPE="checkbox" id="english" name="language"/>English</td></tr> <tr><td>State :</td><td><select name="state" id="state" width="21"> <option value="ap">Andhrapradesh</option> <option value="mp">Madhyapradesh</option> <option value="mh">Maharashtra</option> <option value="delhi" >Delhi</option> <option value="mumbai">Mumbai</option> <option value="SELECT" selected>SELECT...</option></td></tr> </select> <tr> <td><INPUT TYPE="button" value="Submit" onclick="validation()"/></td> <td><INPUT TYPE="reset" value="Reset" onclick="reset()"/></td> </tr> </table> </BODY> </HTML>

15 NIET

JAVA & WEB TECHNOLOGIES

16 NIET

JAVA & WEB TECHNOLOGIES

3. Create a JavaBeans which gives the exchange value of INR (Indian Rupee) into equivalent American/Canadian/Australian Dollar Value. //Converter Bean
package beans.feroz; public class Converter { public Converter() { System.out.println("The following are the converted of INR"); } public double convertToAmerican(double inr) { return (inr /43.50); } public double convertToCanadian(double inr) { return (inr /45.70); } public double convertToAuatralian(double inr) { return (inr /53.50); } }

//Converter Bean Implementation


import beans.feroz.Converter; import javax.swing.JOptionPane; import java.text.DecimalFormat; class ConverterImpl { public static void main(String[] args) { double INR=Double.parseDouble(JOptionPane.showInputDialog("Enter The Indian Rupee(INR)")); Converter con=new Converter(); DecimalFormat df = new DecimalFormat("0.000"); double america = con.convertToAmerican(INR); double canadian = con.convertToCanadian(INR); double australian = con.convertToAuatralian(INR); JOptionPane.showMessageDialog(null,"American Value :"+df.format(america)+"$\nCanadian Value :"+df.format(canadian)+"$\nAustralian Value :"+df.format(australian)+"$"); } }

17 NIET

JAVA & WEB TECHNOLOGIES

18 NIET

JAVA & WEB TECHNOLOGIES

4. Create a XML file that stores the 10 students profiles and develop an application that prompts the student id and display the data in web page using JavaScript DOM college.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <DATABASE> <STUDENT> <NAME>MD Feroz</NAME> <ROLL>1214</ROLL> <NP>80</NP> <WT>80</WT> <DWDM>80</DWDM> <MAD>80</MAD> <SPM>80</SPM> <ACA>56</ACA> <NPLAB>65</NPLAB> <WTLAB>65</WTLAB> </STUDENT> <STUDENT> <NAME>MD Fasi</NAME> <ROLL>1002</ROLL> <NP>81</NP> <WT>81</WT> <DWDM>81</DWDM> <MAD>81</MAD> <SPM>81</SPM> <ACA>56</ACA> <NPLAB>56</NPLAB> <WTLAB>45</WTLAB> </STUDENT> <STUDENT> <NAME>Khaja Afzal</NAME> <ROLL>1003</ROLL> <NP>81</NP> <WT>80</WT> <DWDM>80</DWDM> <MAD>80</MAD> <SPM>80</SPM> <ACA>56</ACA> <NPLAB>78</NPLAB> <WTLAB>56</WTLAB> </STUDENT> <STUDENT> <NAME>Mr.Vishwanath</NAME> 19 NIET

JAVA & WEB TECHNOLOGIES <ROLL>1004</ROLL> <NP>65</NP> <WT>65</WT> <DWDM>65</DWDM> <MAD>56</MAD> <SPM>56</SPM> <ACA>56</ACA> <NPLAB>58</NPLAB> <WTLAB>56</WTLAB> </STUDENT> <STUDENT> <NAME>PLUTO</NAME> <ROLL>1005</ROLL> <NP>65</NP> <WT>65</WT> <DWDM>65</DWDM> <MAD>56</MAD> <SPM>56</SPM> <ACA>56</ACA> <NPLAB>56</NPLAB> <WTLAB>45</WTLAB> </STUDENT> <STUDENT> <NAME>GARFIELD</NAME> <ROLL>1006</ROLL> <NP>45</NP> <WT>65</WT> <DWDM>87</DWDM> <MAD>88</MAD> <SPM>85</SPM> <ACA>56</ACA> <NPLAB>34</NPLAB> <WTLAB>54</WTLAB> </STUDENT> <STUDENT> <NAME>SCROOGE</NAME> <ROLL>1007</ROLL> <NP>98</NP> <WT>85</WT> <DWDM>56</DWDM> <MAD>87</MAD> <SPM>78</SPM> <ACA>56</ACA> <NPLAB>63</NPLAB> <WTLAB>47</WTLAB> </STUDENT>

20 NIET

JAVA & WEB TECHNOLOGIES

Marks.html
<html> <head> <title>RESULT</title> <script type="text/javascript"> var str; function f(str) { var flag = 0,index = 0; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","college.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var Number_Of_Students=xmlDoc.getElementsByTagName("STUDENT").length; for(index=0; index<Number_Of_Students; index++) { if(xmlDoc.getElementsByTagName("ROLL") [index].childNodes[0].nodeValue==str) { flag = 1; break; } } if(flag==0) { document.getElementById("span").innerHTML = "<table cellspacing='30' id='tab' align='center'><tr><td>"+"INCORRECT ROLL NUMBER"+"</td></tr></table>"; } else { var name = xmlDoc.getElementsByTagName("NAME")[index].childNodes[0].nodeValue; var roll = xmlDoc.getElementsByTagName("ROLL")[index].childNodes[0].nodeValue; var np = xmlDoc.getElementsByTagName("NP")[index].childNodes[0].nodeValue; var wt = xmlDoc.getElementsByTagName("WT")[index].childNodes[0].nodeValue; var dwdm = xmlDoc.getElementsByTagName("DWDM")[index].childNodes[0].nodeValue; var mad = xmlDoc.getElementsByTagName("MAD")[index].childNodes[0].nodeValue; var spm = xmlDoc.getElementsByTagName("SPM")[index].childNodes[0].nodeValue; 21 NIET

JAVA & WEB TECHNOLOGIES var aca = xmlDoc.getElementsByTagName("ACA")[index].childNodes[0].nodeValue; var nplab = xmlDoc.getElementsByTagName("NPLAB")[index].childNodes[0].nodeValue; var wtlab = xmlDoc.getElementsByTagName("WTLAB")[index].childNodes[0].nodeValue; var total= parseInt(np)+parseInt(wt)+parseInt(dwdm)+parseInt(mad)+parseInt(spm)+parseInt(aca) +parseInt(nplab)+parseInt(wtlab); var percent= Math.ceil(total * 100 / 750); document.getElementById("span").innerHTML = "<table cellspacing='30' id='tab' align='center'><tr><td>"+"<table id='tab' align='center' border=1 cellpadding='4'>"+"<tr><td>NAME</td><td>:</td><td>"+name+"</td></tr>"+"<tr><td>ROLL</t d><td>:</td><td>"+roll+"</td></tr>" +"<tr><td colspan='3'><hr></td></tr>" +"<tr><td>Network Programming</td><td>:</td><td>"+np+"</td></tr>" +"<tr><td>Web Technologies </td><td>:</td><td>"+wt+"</td></tr>" +"<tr><td>Data Warehousing and Data Mining </td><td>:</td><td>"+dwdm+"</td></tr>" +"<tr><td>Advanced Computer Architecture</td><td>:</td><td>"+aca+"</td></tr>" +"<tr><td>Multimedia and Application Development</td><td>:</td><td>"+mad+"</td></tr>" +"<tr><td>Software Project Management</td><td>:</td><td>"+spm+"</td></tr>" +"<tr><td>Network Programming Lab </td><td>:</td><td>"+nplab+"</td></tr>" +"<tr><td>Web Technologies Lab </td><td>:</td><td>"+wtlab+"</td></tr>" +"<tr><td colspan='3'>&nbsp;</td></tr>" +"<tr><td>TOTAL</td><td>:</td><td>"+total+"</td></tr>" +"<tr><td>PERCENTAGE</td><td>:</td><td>"+percent+"</td></tr>" +"</table>" +"</td></tr></table>"; } } </script> <style> #roll { padding-left:5; } input { background-color:#333; color:white; border:none; font-size:16px; font-family:Verdana, Geneva, sans-serif; height:30px; } #tab { background-color:#333; color:white; }

22 NIET

JAVA & WEB TECHNOLOGIES #result, body { background-color:#CCC; } #footer { background-color:#333; color:white; font-size:16px; font-family:Verdana, Geneva, sans-serif; bottom:0px; height:45px; width:100%; position:fixed; z-index:3; text-align:center; left:0px; } </style> </head> <body align="center"> <br/><br/> <div align="center"> <table><tr> <td><input type="text" id="roll" onkeyup="javascript:this.value = this.value.toUpperCase();"/></td> <td><input type="button" value="Get Marks" onClick="f(document.getElementById('roll').value);"/></td> </tr></table> </div> <br/> <div align="center" id="result" > <font face="Verdana, Geneva, sans-serif" > <span id="span" width="700" height="500" align="center"></span> </font> </div> <div id="footer"> <p>Md Feroz Khanani &copy; 2010 </p> </div> </body> </html>

23 NIET

JAVA & WEB TECHNOLOGIES

5. Write a Java bean program which converts rupees into dollar value, your program must accept the rupees value from the properties window in which rupees property is set. The display of dollar value must be on the BeanBox.
24 NIET

JAVA & WEB TECHNOLOGIES package royal.feroz; import javax.awt.event.*; import java.awt.*; import java.text.*; public class CurrencyConverter extends Canvas { private String rupees; private double eRate=0.017; private NumberFormat fmt = NumberFormat.getInstance(); public CurrencyConverter() { setSize(70,70); rupees="1.0"; change(); } public String getRupees() { return rupees; } public void setRupees(String rupees) { this.rupees = rupees; } public void change() { rupees = getValue() repaint(); } private String getValue() { double value = Double.parseDouble(rupees); value = value*eRate; fmt.setMaximumFractionDigits(3); fmt.setMiniimumFractionDigits(3); rupees = "$"+fmt.format(value); return rupees; } public void paint(Graphics g) { g.drawString(rupees,10,10); } }

STEPS FOR EXECUTION


25 NIET

JAVA & WEB TECHNOLOGIES step-1 : Create a folder converter at a location c:\beans\demo\sunw\demo\ and save the file name as CurrencyConverter.java step-2 : Compile this program as javac d . CurrencyConverter.java , a class file is generated at that location. step-3 : Create a manifest file(mft) as CurrencyConverter.mft at the location as follows Name:sunw/demo/converter/CurrencyConverter.class Java-Bean:True step-4 : Then create a Jar file by using the following command c:\beans\demo\jar cfm ..\jars\CurrencyConverter.jar CurrencyConverter.mft

6. Write a simple java Bean program for generating the traffic signal.. package royal.feroz; 26 NIET

JAVA & WEB TECHNOLOGIES import javax.awt.event.*; import java.awt.*; public class TrafficSignal extends Canvas { private Color color; public int flag = 1; public int red = 0; public int green = 255; public int blue = 0; public TrafficSignal() { setSize(70,70); change(); } public void change() { color = randomColor() repaint(); } private Color randomColor() { //green turn to orange if((red==0) && (green==255) && (blue==0)) { red = 250; green=200;//orange = red+green blue=0; } //orange turn to red else if((red==250) && (green==200) && (blue==0)) { red = 255; green=0;//red=stop blue=0; } // default set to green else { red = 0; green=255;//orange = red+green= see and go blue=0; } return new Color(red, green,blue); } public void paint(Graphics g) 27 NIET

JAVA & WEB TECHNOLOGIES { g.drawRect(0,0,35,95); g.drawOval(2,2,31,31); g.drawOval(2,32,31,31); g.drawOval(2,63,31,31); if(flag == 1)// flag =1 means green color { g.setColor(color); g.fillOval(2,63,31,31); flag=2; } else if(flag ==2)// flag =2 means orange color { g.setColor(color); g.fillOval(2,32,31,31); flag=3; } else // flag =3 means green color { g.setColor(color); g.fillOval(2,63,31,31); flag=1; } } }

7 . Write a java program that demonstrates all the swing GUI components to create a user form
28 NIET

JAVA & WEB TECHNOLOGIES import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Form extends JFrame { JTextField name_t,rno_t; JLabel name_lb,rno_lb,branch_lb,gender_lb,dob_lb,hobbies_lb,languages_lb; JComboBox branch_com,yy_com,mm_com,dd_com; JRadioButton m,f; JList hobbies_lst; JCheckBox eng,hin,tlg,urd; JButton submit,cancel; public Form() { name_t = new JTextField(10); rno_t = new JTextField(10); name_t.setBackground( Color.yellow); rno_t.setBackground( Color.yellow); name_lb = new JLabel("Name:"); rno_lb = new JLabel("Rollnumber:"); branch_lb = new JLabel("Branch:"); gender_lb = new JLabel("gender:"); dob_lb= new JLabel("Date of Birth:"); hobbies_lb = new JLabel("Hobbies:"); languages_lb = new JLabel("Languages:"); String br_name[]={"CSIT","CSE","ECE","MECH","EEE"}; branch_com= new JComboBox(br_name); yy_com = new JComboBox(); for(int i=1982;i<=2008;i++) { Integer a = new Integer(i); yy_com.addItem(a.toString()); } String mm_name[]={"JAN","FEB","MARCH","APRL","MAY","JUNE","JULY","AUG"}; mm_com = new JComboBox(mm_name); String dd_name[]={"01","02","03","04","05","06","07","08","09","10"}; dd_com= new JComboBox(dd_name); eng=new JCheckBox("ENGLISH"); hin=new JCheckBox("HINDI"); tlg=new JCheckBox("TELUGU"); urd=new JCheckBox("URDU"); ButtonGroup bg = new ButtonGroup(); m=new JRadioButton("MALE"); f=new JRadioButton("FEMALE"); bg.add(m); bg.add(f); String hb_name[]={"CRICKET","FOOTBALL","HOCKEY"}; 29 NIET

JAVA & WEB TECHNOLOGIES hobbies_lst = new JList(hb_name); submit= new JButton("Submit"); cancel= new JButton("Cancel"); Container c = getContentPane(); //c.setBackground( Color.lightGray); c.setLayout(new FlowLayout()); c.add(name_lb); c.add(name_t); c.add(rno_lb); c.add(rno_t); c.add(branch_lb); c.add(branch_com); c.add(gender_lb); c.add(m); c.add(f); c.add(dob_lb); c.add(yy_com); c.add(mm_com); c.add(dd_com); c.add(hobbies_lb); c.add(hobbies_lst); c.add(languages_lb); c.add(eng); c.add(hin); c.add(tlg); c.add(urd); c.add(submit); c.add(cancel); setSize(300,250); setVisible(true); } public static void main(String[] args) { Form f = new Form(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); } }

30 NIET

JAVA & WEB TECHNOLOGIES

8. Install the TOMCAT SERVER & Write a java servlets that displays a simple message. And create a Directory Structure of web application.
31 NIET

JAVA & WEB TECHNOLOGIES Directory Structure

Tomcat

Webapps

MyAppl

Jsps/html

WEB-INF

Web.xml

Classes Lib

Java .class Files

web.xml
<web-app> <display-name>SERVLET-MESSAGE</display-name> <servlet> <servlet-name>ServletExample</servlet-name> <servlet-class>com.ServletExample</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletExample</servlet-name> <url-pattern>/feroz/*</url-pattern> </servlet-mapping> </web-app>

ServletExample.java 32 NIET

JAVA & WEB TECHNOLOGIES package com; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class ServletExample extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>BasicServlet</title></head>"); out.println("<body bgcolor='green'>"); out.println("<br><br><br><center><h1>WELCOME TO SERVLET EXAMPLE......</h1></center>"); out.println("</body></html>"); out.close(); } }

9. Write a servlet program that reads Initialization parameters from web.xml file.
<web-app> 33 NIET

JAVA & WEB TECHNOLOGIES <display-name>READING -INITIALIZATION-PARAM</display-name> <servlet> <servlet-name>ServletInitialization</servlet-name> <servlet-class>com.ServletInitialization</servlet-class> <init-param> <param-name>Student Name :</param-name> <param-value>MD FEROZ </param-value> </init-param> <init-param> <param-name>Branch Name :</param-name> <param-value>C.S.E</param-value> </init-param> <init-param> <param-name>ROLL NUMBER :</param-name> <param-value>02661A1214 </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ServletInitialization</servlet-name> <url-pattern>/feroz/*</url-pattern> </servlet-mapping> </web-app> ServletInitialization.java package com; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class ServletInitialization extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); StringBuffer buffer = new StringBuffer(); out.println("<html>"); out.println("<head><title>BasicServlet</title></head>"); out.println("<body bgcolor='pink'>"); out.println("<center><h2><u>READING THE INITIALIZATION PARAMETERS</u></h2>"); 34 NIET

JAVA & WEB TECHNOLOGIES Enumeration parameters =getServletConfig().getInitParameterNames(); while(parameters.hasMoreElements()) { String parameter =(String)parameters.nextElement(); out.println("<br>"+parameter+" :"); out.println(getServletConfig().getInitParameter(parameter)); out.println("</br>"); } out.println("</center></body></html>"); out.close(); } }

10. Write the Servlet that Demonstrate the Http Session Tracking.
package com; 35 NIET

JAVA & WEB TECHNOLOGIES import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.Date; public class ServletSession extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Session Tracking </title></head>"); out.println("<body bgcolor='#FFC68C'><center>"); HttpSession session = request.getSession(); if(session.isNew()) session.setAttribute("pageCount",1); int count = (Integer)session.getAttribute("pageCount"); session.setAttribute("pageCount",count+1); out.println("<BR><BR><BR><FONT COLOR='blue' size='18' type='bold'>You Accessed the Page :"); out.println("<u>"+count+"</u></font>"); out.println("<br><h2>CURRENT DATE : "+new Date().toString()); out.println("<br>SESSION ID :"+session.getId()); out.println("<br>MAXIMUM INACTIVE INTERVAL :"+session.getMaxInactiveInterval()); out.println("<br><p><u>CLICK REFRESH TO RELOAD THE PAGE</u></p>"); out.println("</body></html>"); } }

11. JSP script that converts the static pages of task1 (Home page).
36 NIET

JAVA & WEB TECHNOLOGIES A) Home.jsp <%@ page language="java" contentType="text/html"%> <html> <head><title>Royal Online Shopping </title> </head> <body bgcolor="#408080"> <table width="100%" border="0" cellspacing="3" bgcolor="#CEA953"> <tr> <td colspan="8"> <%@ include file="top.jsp" %> </td> </tr> <tr height="70%"> <td align="top" bgcolor="#E9E37C" colspan="6"> <%@ include file="left.jsp" %> </td> <td align="main" bgcolor="#C2C287"> <%@ include file="main.jsp" %> </td> </tr> <tr> <td colspan="8"> <%@ include file="marquee.html"%> </td> </tr> </table> </body> </html> B) left.jsp <div align="left">Search <input name="search" type="text" id="search" size="8" /> <br /> <p>Product Catalog : </p> <ul> <li><a href="Mobiles.html>Mobiles</a></li> <li><a href="Computers.html">Computers</a></li> <li><a href="Book.html>Books</a></li> <li><a href="Electronics.html">Electronics</a></li> </ul> </div>

C) top.jsp 37 NIET

JAVA & WEB TECHNOLOGIES <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td height="84"> <img src="../Images/books_logo.gif" alt="LOGO" width="100" height="77"/> </td> <td align="center"> <FONT TYPE="BOLD" SIZE="6" COLOR="red">ROYAL ONLINE SHOPPING CENTER....</FONT> </td> </tr> </table> </div> D) Main.jsp <body> <center><strong>Please Authenticate <br> <table width="50%" height="78" border="1" align="center" bgcolor="#408080"> <tr> <th width="114" height="39" align="center"><strong>User Name </strong></th> <th width="101" scope="col"><input type="text" name="textfield" style="backgroundcolor='#CEA953' "/></th> </tr> <tr> <td height="24" align="center" ><strong>Password</strong></td> <td><input name="password" type="password" id="password" style="background-color='#CEA953' "/></td> </tr> </table> <input type="submit" name="Submit" value="Submit" style="cursor:pointer" /> </body> </html> E) marquee.html <div align="center"> <font color="#9D7B2D" size="5"> <Marquee>Welcome to Royal Online Shopping..............Feroz....</marquee> </font> </div>

38 NIET

JAVA & WEB TECHNOLOGIES

12. Generate the Dynamic Contents Using JSP Standard actions.


39 NIET

JAVA & WEB TECHNOLOGIES UseBean.jsp <body bgcolor="#FFCCFF"> <form method="post"> <center> <table width="50%" border="1"> <tr> <td>Name:</td><td><input type="text" name="name"></td> </tr> <tr> <td>Branch:</td><td><input type="text" name="branch"></td> </tr> <tr> <td>RollNumber:</td><td><input type="text" name="rollNum"></td> </tr> </table> <input type="submit" value="Submit"> </form> <jsp:useBean id="bean" class="beans.feroz.BeanExample"/> <jsp:setProperty name="bean" property="*"/> <h2>You Entered :</h2> <table border="1" bgcolor="pink" width="50%"> <tr> <th>Name :</th> <td> <jsp:getProperty name="bean" property="name"/></td> </tr> <tr> <th>Branch :</th> <td><jsp:getProperty name="bean" property="branch"/></td> </tr> <tr> <th>RollNumber :</th> <td><jsp:getProperty name="bean" property="rollNum"/></td> </tr> <table> </body>

40 NIET

JAVA & WEB TECHNOLOGIES

13. Create an Application that demonstrates a JDBC connection.


41 NIET

JAVA & WEB TECHNOLOGIES import java.io.*; import java.sql.*; import javax.swing.JOptionPane; public class DatabaseAccess { public static void main(String[] args) { String name="",roll="",branch="",m1="",m2="",m3="",result=""; int total,marks1,marks2,marks3; double average; String rollNumner = JOptionPane.showInputDialog("Enter The Roll Number:"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("LOADING THE DRIVER PLASE WAIT.........."); } catch(Exception e){} try { System.out.println("CREATING THE CONNECTION................."); Connection con = DriverManager.getConnection("jdbc:odbc:FerozOne"); System.out.println("DATABASE CONNECTION CREATED SUCCESSFULLY"); Statement statement = con.createStatement(); String sql="SELECT RollNumber,Name,Branch,Marks1,Marks2,Marks3 FROM student WHERE RollNumber='"+rollNumner+"'"; System.out.println("EXECUTING THE QUERY PLEASE WAIT........."); ResultSet resultset = statement.executeQuery(sql); System.out.println("GENERATING THE RESULTANT OUTPUT....."); while(resultset.next()) { roll=resultset.getString(1); name=resultset.getString(2); branch=resultset.getString(3); m1=resultset.getString(4); m2=resultset.getString(5); m3=resultset.getString(6); } } catch(SQLException e){System.out.println(e.getMessage());} marks1=Integer.parseInt(m1); marks2=Integer.parseInt(m2); marks3=Integer.parseInt(m3); total=marks1+marks2+marks3; average=total/3; if(average>40.0) 42 NIET

JAVA & WEB TECHNOLOGIES { result="PASS"; } else result="FAILED"; JOptionPane.showMessageDialog(null,"Name : " +name+"\nBranch : " +branch+"\nRollNumber : " +roll+"\nTotal marks Secured : "+total+"\nAverage marks : " +average+"\nResult : " +result); } }

14. Design a Web Application which follows MVC Architecture Using JDBC.
43 NIET

JAVA & WEB TECHNOLOGIES Model and View Controller (MVC)

Controll er

CLIENT
VIEW

Mod el

Database

Login.java (ControllerServlet) package com; import javax.servlet.*; import javax.servlet.http.*; import java.util.Date; import java.io.*; public class Login extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); out.println("<HTML><TITLE>Login Page</TITLE>"); out.println("<HEAD><h1><CENTER><u>Welcome To Royal College</u></h1></CENTER></HEAD>"); out.println("<BODY bgcolor='#99C9DB' ><CENTER>"); out.println("<FONT size='6' color='red'>Please Authenticate.... "); out.println("<FORM METHOD='post' ACTION='../jsp/loginsuccess.jsp'>"); out.println("<TABLE BGCOLOR='#99C9DB' border='1'>"); out.println("<tr><td>USERNAME : </td><td><input type='text' NAME='name' id='name' SIZE=12></td></tr>"); out.println("<br><tr><td>PASSWORD : </td><td><input type='password' NAME='password' id='password' SIZE=12></td></tr>"); out.println("</TABLE>"); out.println("<br><INPUT TYPE='SUBMIT' VALUE='Submit' align='center' style='cursor:pointer'>"); out.println("</FORM>"); if (req.getParameter("error")!=null) out.println("<FONT COLOR='red' size='4' NAME='georgia'>Login failed, Please try again.<BR></font>"); 44 NIET

JAVA & WEB TECHNOLOGIES out.println("<BODY></HTML>"); } } LoginSuccess.jsp (A JBDC Connection jsp file) <TITLE> SUCCESS PAGE </TITLE> <%@ page import="java.sql.*" %> <%@ page import="java.util.*" %> <%@ page import="javax.servlet.*, javax.servlet.http.*" %> <BODY bgcolor="#99C9DB"> <% System.out.println("IN LOGIN SUCCESS PAGE"); String name=request.getParameter("name"); String password=request.getParameter("password"); System.out.println("NAME=="+name+"\nPassword=="+password); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("JDBC driver loaded"); Connection connection = DriverManager.getConnection("jdbc:odbc:Royal","",""); System.out.println("CONNECTED TO THE DATABASE"); Statement statement = connection.createStatement() ; System.out.println("Query Executing"); ResultSet resultset=statement.executeQuery("SELECT ID,UserName FROM Login Where UserName= '"+name+"' AND Password='"+password+"'"); System.out.println("Query Executed"); System.out.println("getting the id's of all user names"); if (resultset.next()) { int id=resultset.getInt("ID"); System.out.println("ID=="+id); System.out.println("Name=="+resultset.getString(2)); System.out.println("REDIRECTING TO THE Success PAGE"); RequestDispatcher rd=request.getRequestDispatcher("../jsp/Success.jsp?UserName="+name); rd.include(request,response); } else { System.out.println("REDIRECTING TO THE LOGIN PAGE"); response.sendRedirect("/Royal/feroz/Login.java?error=yes"); } }catch(Exception e){System.out.println("FEROZ ERROR="+e);} %> </BODY>

Success.jsp 45 NIET

JAVA & WEB TECHNOLOGIES <BODY bgcolor="#99C9DB"><h3><br> <CENTER> AUTHENTICATION IS SUCCESSFULL.. <br> Hi,<%=request.getParameter("UserName") %> <%@ page import="java.util.*" %> <% Date d = new Date(); %> Time :<%=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds() %> </CENTER> </BODY>

Invalid user/Password page. 46 NIET

JAVA & WEB TECHNOLOGIES

Success.jsp

47 NIET

JAVA & WEB TECHNOLOGIES

15. Create a web-app that SEARCH data from database..


A) search.html <HTML> <HEAD> <STYLE> .btn { background-image:url("..\images\button.png"); background-repeat:repeat-x; background-color:white; background-position:center; text-align:center; cursor:pointer; } #txt { background-color:"#FFFFCC"; } </STYLE> </HEAD> <BODY BGCOLOR="#F7E1DF"> <CENTER><BR> <FONT COLOR="#FF6699" SIZE="6" STYLE="GEORGIA"> ROYAL ONLINE SHOPPING... </FONT> <TABLE> <TR> <FORM method="post" action="SearchAction.jsp"> <TD> <INPUT type="text" size="15" name="keyword" id="txt"/> <INPUT type="submit" value="SEARCH" class="btn" /> </TD> </TR> <FORM> </TABLE> </BODY>

48 NIET

JAVA & WEB TECHNOLOGIES B) searchAction.jsp <%@ page import="java.util.*,java.sql.*,javax.servlet.*" %> <%@ page import="javax.servlet.http.*,com.Product" %> <jsp:useBean id="searchBeanId" scope="application" class="com.DbBean"/> <jsp:useBean id="product" scope="application" class="com.Product"/> <body bgcolor="#F7E1DF"> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exception e){System.out.println("ERRORRRR====="+e);} System.out.println("Database Driver Loaded Successfuly "); %> <% String keyword=request.getParameter("keyword"); if (keyword!=null && !keyword.trim().equals("")) { ArrayList products = searchBeanId.getSearchResults(keyword); System.out.println("$$$$$ Gettting the products from Bean Database $$$$$$$$$$$$$$"); Iterator iterator = products.iterator(); if(iterator.hasNext()) { %> <CENTER><BR><BR> <FONT SIZE="4" COLOR="red">RECORDS FOUND FOR "<%=keyword %>" </FONT> <TABLE BORDER="1" BGCOLOR="#E7B7AB" WIDTH="60%"> <TR> <TH width="30%">NAME</TH> <TH width="30%">DESCRIPTION</TH> <TH width="30%">PRICE</TH> </TR> </TABLE> <% } int count=0; while (iterator.hasNext()) { product = (Product) iterator.next(); count++; %> <TABLE BORDER="1" BGCOLOR="#E7B7AB" WIDTH="60%"> <TR> <TD width="30%"><%=product.name%></TD> <TD width="30%"><%=product.description%></TD> <TD width="30%"><%=product.price%></TD> </TR> 49 NIET

JAVA & WEB TECHNOLOGIES </TABLE> <% } if(count>0) { %> <BR><BR> <TABLE BGCOLOR="#FFFFCC"> <TR> <TD>NUMBER OF RECORDS FOUND : <u><%= count %></TD> </TR> </TABLE> <% } } else { out.println("<BR><BR><CENTER><TABLE BGCOLOR='#FFFFFF'>"); out.println("<TR><TD>PLEASE ENTER A SEARCH KEYWORD </TD></TR></TABLE>"); } %> C) product.java package com; public class Product { public int id; public String name; public String description; public double price; }

50 NIET

JAVA & WEB TECHNOLOGIES D) DbBean.java (A data Base Bean java file) package com; import java.util.Hashtable; import java.util.ArrayList; import java.util.Enumeration; import java.sql.*; public class DbBean { public ArrayList getSearchResults(String keyword) { ArrayList products = new ArrayList(); try { Connection connection = DriverManager.getConnection("jdbc:odbc:FerozOne","",""); System.out.println("$$$$$ Database is connected $$$$$$$$$$$$$$"); Statement s = connection.createStatement(); System.out.println("$$$$$ Statement is created $$$$$$$$$$$$$$"); String sql = "SELECT ID, ProductName, Description, Price FROM Products" + " WHERE ProductName LIKE '%" + keyword.trim() + "%'"; System.out.println("$$$$$ EXECUTING THE QUERY............ $$$$$$$$$$$$$$"); ResultSet rs = s.executeQuery(sql); System.out.println("$$$$$ Query is executed $$$$$$$$$$$$$$"); while (rs.next()) { Product product = new Product(); product.id = rs.getInt(1); product.name = rs.getString(2); product.description = rs.getString(3); product.price = rs.getDouble(4); products.add(product); } rs.close(); s.close(); connection.close(); } catch (SQLException e) {} return products; } }

51 NIET

JAVA & WEB TECHNOLOGIES

52 NIET

JAVA & WEB TECHNOLOGIES

16. Write a JSP script that select inserts and updates the user information forms using JDBC.
A) DataBaseBean.java package com; import java.sql.*; public class DataBaseBean { int ID=0; public int insertIntoDataBase(int id, String name, String add, String email, String mob, String CCN) { int res=0; try { Connection connection = DriverManager.getConnection("jdbc:odbc:FerozOne","",""); System.out.println("DataBase Is Connected to FerozOne(users) FOR INSERT RECORD"); id=id+3; System.out.println("NEW ID IS CREATED : " +id); Statement statement = connection.createStatement() ; String sql="INSERT INTO users(ID,Name,Address,Email,Mobile,CCNumber)"+ "VALUES('"+id+"','"+name+"','"+add+"','"+email+"','"+mob+"','"+CCN+"')"; System.out.println("Query is Executed FOR INSERT"); System.out.println("----------------------------------------------------------"); res = statement.executeUpdate(sql); System.out.println("Result set Value "+ res); }catch(Exception e){} return res; } public ResultSet getDetails(int id) { ID=id; ResultSet resultset=null; try { Connection connection = DriverManager.getConnection("jdbc:odbc:FerozOne","",""); System.out.println("DataBase Is Connected to FerozOne(users) FOR SELECT"); System.out.println("----------------------------------------------------------"); Statement statement = connection.createStatement() ; String sql="SELECT Name, Address, Email, Mobile, CCNumber FROM users WHERE ID="+ID+""; resultset = statement.executeQuery(sql); System.out.println("Query is Executed FOR SELECT"); System.out.println("----------------------------------------------------------"); }catch(Exception e){} return resultset; 53 NIET

JAVA & WEB TECHNOLOGIES } public int updateRecord(String name, String add, String email, String mob, String CCN, int id) { int res=0; try { Connection connection = DriverManager.getConnection("jdbc:odbc:FerozOne","",""); System.out.println("DataBase Is Connected to FerozOne(users) FOR UPDATE"); System.out.println("----------------------------------------------------------"); Statement statement = connection.createStatement() ; System.out.println("Updating the record of ID : " +id ); String sql="UPDATE users SET Name=' "+name+"', Address=' "+add+" ', Email=' "+email+" ', Mobile='"+mob+"', CCNumber='"+CCN+" ' WHERE ID="+id+""; res = statement.executeUpdate(sql); System.out.println("Query is Executed FOR UPDATE"); System.out.println("----------------------------------------------------------"); System.out.println("Result set Value "+ res); } catch(Exception e){System.out.println(e);} return res; } public int getID() { int res=0; ResultSet resultset=null; try { Connection connection = DriverManager.getConnection("jdbc:odbc:FerozOne","",""); System.out.println("DataBase Is Connected to FerozOne(users) FOR UPDATE"); System.out.println("----------------------------------------------------------"); Statement statement = connection.createStatement() ; String sql="SELECT ID FROM users"; resultset = statement.executeQuery(sql); System.out.println("Query is Executed FOR SELECT ID"); System.out.println("----------------------------------------------------------"); while(resultset.next()) { res = resultset.getInt(1); } System.out.println("Result set Value ID "+ res); } catch(Exception e){} return res; } }

54 NIET

JAVA & WEB TECHNOLOGIES B) index.jsp <HTML> <HEAD> <LINK rel="stylesheet" type="text/css" href="../css/users.css"/> </HEAD> <BODY BGCOLOR="#E7B7AB"> <CENTER><h1><blink>WELCOME TO ROYAL ONLINE SHOPPING...</blink> </h1> <FONT COLOR="#FF6699" SIZE="6" STYLE="GEORGIA"><u><br> Enter The User Id .. </FONT> <FORM method="post" action="getDetails.jsp"> <TABLE> <TR> <TD> <INPUT type="text" size="10" name="keyword" id="txt"/> <INPUT type="submit" value="GetDetails" class="btn" /> <a href="newUser.jsp?" target="_self">New user ?</a> </TD> </TR> </TABLE> </FORM> </BODY> C) getDetails.jsp

<jsp:useBean id="getId" class="com.DataBaseBean" scope="application"/> <%@ page import="java.sql.*"%> <HEAD> <TITLE>GETTING DATA </TITLE> </HEAD> <BODY bgcolor="#E7B7AB"> <jsp:include page="index.jsp"/> <% ResultSet resultset=null; int id = Integer.parseInt(request.getParameter("keyword")); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Database Driver Loaded Successfully :"); System.out.println("----------------------------------------------------------"); } catch(Exception e){} resultset=getId.getDetails(id); while(resultset.next()) { %> 55 NIET

JAVA & WEB TECHNOLOGIES <FORM METHOD="POST" ACTION='update.jsp?ID=<%= request.getParameter("keyword") %>'> <table width="250" border="1" align="center"> <tr> <td><strong> Name </td> <td><input type="text"name="name" id="name" value="<%= resultset.getString(1) %>" /></td> </tr> <tr> <td><strong>Address</strong></td> <td><input type="text" name="address" id="address" value="<%= resultset.getString(2) %>" /></td> </tr> <tr> <td><strong>e@mail</strong></td> <td><input type="text"name="email" id="email" value="<%= resultset.getString(3) %>" /></td> </tr> <tr> <td><strong>Mobile</strong></td> <td><input type="text" name="mobile" id="mobile" value="<%= resultset.getString(4) %>" /></td> </tr> <tr> <td><strong>CC Number</strong></td> <td><input type="text" name="creditcardnumber" id="creditcardnumber" value="<%= resultset.getString(5) %>" /></td> </tr> </table> <%}%> <br> <CENTER> <table> <tr> <td><input type="submit" value="Update" style="cursor:pointer" class="btn" /></td> </tr> </table> </FORM> </BODY> </HTML>

56 NIET

JAVA & WEB TECHNOLOGIES D) newUser.jsp <HTML> <HEAD> <TITLE>NEW USER </TITLE> <LINK rel="stylesheet" type="text/css" href="../css/users.css"/> </HEAD> <jsp:useBean id="getId" class="com.DataBaseBean" scope="application"/> <BODY bgcolor="#E7B7AB"><CENTER> <h1><blink>WELCOME TO ROYAL ONLINE SHOPPING...</blink> </h1> <FONT color="red" size="3"><i><strong>PLEASE FILL THE REGISTRATION FORM.... </FONT> <br> <% try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Database Driver Loaded Successfully :"); System.out.println("----------------------------------------------------------"); }catch(Exception e){} int id = getId.getID(); System.out.println("THE LAST ID :"+id); %> <form METHOD="POST"action="insert.jsp?ID=<%= getId.getID() %>"> <table width="250" border="1" align="center"> <tr> <td><strong> Name </td> <td><input type="text" name="name" id="name" /></td> </tr> <tr> <td><strong>Address</strong></td> <td><input type="text" id="address" name="address"/></td> </tr> <tr> <td><strong>e@mail</strong></td> <td><input type="text" id="email" name="email"/></td> </tr> <tr> <td><strong>Mobile</strong></td> <td><input type="text" id="mobile" name="mobile" /></td> </tr> <tr> <td><strong>CC Number</strong></td> <td><input type="text" id="creditcardnumber" name="creditcardnumber" /></td> </tr> </table> <table width="200" border="1" align="center"> <tr> 57 NIET

JAVA & WEB TECHNOLOGIES <th height="23"> <input type="submit" value="Submit"/> </th> </tr> </table> <FORM> </BODY> </HTML> E) insert.jsp <jsp:useBean id="insertId" class="com.DataBaseBean" scope="application"/> <HTML> <HEAD> <TITLE>INSERT DATA </TITLE> </HEAD> <BODY bgcolor="#E7B7AB"> <% String mobile,creditCardNumber; int resultset=0; String name,address,email; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Database Driver Loaded Successfully"); name = request.getParameter("name"); address = request.getParameter("address"); email = request.getParameter("email"); mobile = request.getParameter("mobile"); creditCardNumber = request.getParameter("creditcardnumber"); int id=Integer.parseInt(request.getParameter("ID")); System.out.println("THE NEW ID"+id); System.out.println("NAME "+name+"\n ADDRESS="+address+"\nEMAIL-ID :"+email); resultset=insertId.insertIntoDataBase(id, name, address, email, mobile,creditCardNumber); if(resultset>0) { out.println("<br><CENTER><h1><blink>WELCOME TO ROYAL ONLINE SHOPPING...</blink><h1>"); out.println("<br><u><hr><h2>Registration Is Successfully.<hr>"); out.println("<br><u><hr><a href='index.jsp' target='_self '>Home</a><hr>"); } }catch(Exception e){System.out.println("ERROR:"+e.toString());} %> </BODY> </HTML> 58 NIET

JAVA & WEB TECHNOLOGIES F) update.jsp <jsp:useBean id="updateId" class="com.DataBaseBean"/> <BODY bgcolor="#E7B7AB"> <% int resultset=0; String name,address,email,mobile,creditCardNumber; int id=Integer.parseInt(request.getParameter("ID")); name = request.getParameter("name"); address = request.getParameter("address"); email = request.getParameter("email"); mobile = request.getParameter("mobile"); creditCardNumber =request.getParameter("creditcardnumber"); System.out.println("NAME "+name+"\nID="+id); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Database Driver Loaded Successfully"); resultset=updateId.updateRecord(name,address,email,mobile, creditCardNumber,id); if(resultset>0) { out.println("<br><CENTER><h1><blink>WELCOME TO ROYAL ONLINE SHOPPING...</blink><h1>"); out.println("<br><u><hr><h2>Your Record has been Successfully Updated...<hr>"); out.println("<br><u><hr><a href='index.jsp' target='_self '>Home</a><hr>"); } }catch(Exception e){System.out.println("ERROR:"+e.toString());} %> </BODY> </HTML>

59 NIET

JAVA & WEB TECHNOLOGIES

60 NIET

JAVA & WEB TECHNOLOGIES

61 NIET