Webtechnology lab

721 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
721
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Webtechnology lab

  1. 1. Ex.No: HTML PAGES WITH FRAMES, LINKS, TABLESDate :AIM: To create a HTML pages with frames, links, tables and other tags.ALGORITHM: 1. Create a HTML page using <table> tag which displays the content. 2. Create another HTML page using <OL>,<UL> and <LI> tags which displays the content in the list format. 3. Create another HTML page with frames which combines more than one HTML pages. 4. Execute the frame page, feel as dynamic page having more than one page in a single page.
  2. 2. PROGRAM : frame.html<html> <frameset cols="30%,80%"> <frame src="page1.html"> <frameset rows="45%,65%"> <frame src="page2.html"> <frameset cols="30%,30%"> <frame src="page3.html"> <frame src="page4.html"> </frameset> </frameset> </frameset></html> page1.html<html> <body style="background-color:pink"> <font size="3" color="red"> <h><b>THE KAVERY COLLEGES:<b></h></br> <ul> <a href ="fr1.htm">THE KAVERY ENGINEERING COLLEGE</a></br> </ul> <ul> <h>THE KAVERY POLYTECH</h></br> </ul> <ul> <h>THE KAVERY TEACHER TRAINING</h> </ul><ul> <h>IMPORTANT DETAILS:</h></ul><table border="3" style="background-color:red;"> <tr> <td>CHAIRMAN</td> <td>ELENGOVAN</td> <td>9566754710</td> </tr> <tr> <td>PRINCIPAL</td> <td>VENKATACHALAM</td> <td>9566754710</td> </tr>
  3. 3. <tr> <td>CSE HOD</td> <td>SATHISH</td> <td>9566754710</td> </tr> </table></html> page2.html<html> <body style="background-color:pink;"> <font size="6" face="arial" color="red"> <h><center>THE KAVERY ENGINEERING COLLEGE<center></H> <marquee behaviour="style=" direction="right" scrollamount="10"> <h><center>MECHERI</center></h> </marquee> <h><center>AFFLICATED TO ANNA UNIVERSITY-CHENNAI<center></h> <ul> <h>SELECT<sub> KAVERY </sub>FOR <sub>BRIGHTFUTURE</sub></h> </ul> </body></html> page3.html<html> <body style="background-color:pink;"> <font size="3" color="green"> <h><b>THE KAVERY ENGINEERING COLLEGE:<b></H></br> <ul> <h><b><i>COURSE OFFERED:</i></b></H> </ul> <ul> <h><b>UG COURSE:<b></h> <ul> <li>CSE</li> <li>ECE</li> <li>EEE</li> </ul> </ul> <ul> <h><b>PG COURSE:</b></h> <ul> <li>COMPUTER SCIENCE</li>
  4. 4. <li>POWER ELECTRONICS</li> <li>VLSI DESIGN</li> </ul> </ul></html> Page4.html<html> <body style="background-color:pink;"> <font size="3" color="green"> <h><b>KAVERY POLYTECH:</h> <ul> <h>COURSE OFFERED:</h> <ul> <li>CSE</li> <li>AUTOMOBILE</li> <li>CIVIL</li> </ul> </ul></html>
  5. 5. OUTPUT:
  6. 6. RESULT: Thus the given program was coded and executed successfully.
  7. 7. Ex.No:02 HTML WITH INTERNAL AND EXTERNAL CSSDate:AIM: To create a HTML page using internal and external CSSALGORITHM: 1. Create a simple HTML page. 2. Write internal CSS using <style> tag in the same page become internal CSS. 3. Create another CSS file using <style> tag with extension .css file, which becomes external CSS file 4. Include the external CSS file in your file. 5. Find the style changes on your page.PROGRAM: int_ext_css.html<!--- Internal and External CSS Example---><html><head><link rel="stylesheet" type="text/css" href="exter.css" /><style>h1{ text-align:center;}h2{ font-size:30px; text-align:center;}h3{ font-size:30px; text-align:center;}a.three:link {color:#ff0000;}a.three:visited {color:#0000ff;}a.three:hover {background:#66ff66;}a.three{
  8. 8. font-size:30px; text-align:center;}ul{ font-size:30px; color:red; list-style-type:circle;}h4{ font-size:30px; color:red;}ul.pg{ font-size:30px; color:red; list-style-type:square;}</style></head><body><h1>CMS COLLEGE OF ENGINEERING</h1><h2>NAMAKKAL</h2><h3>AFFLICATED TO ANNAUNIVERSITY</H3><P><a class="three" href="default.asp">UG COURSE:</a></p><ul> <li>COMPUTER SCIENCE</li> <li>CIVIL</li> <li>MECHANICAL</li></ul><h4>PG COURSE:</h4><ul class="pg"> <li>COMPUTER SCIENCE</li> <li>POWER ELECTRONICS</li> <li>VLSI DESIGN</li></ul></body></html> exter.css<style>head{
  9. 9. }body{background-color:pink;}h1{color:red;}h2{color:red;}h3{color:red;}</style>
  10. 10. OUTPUT:RESULT: Thus the given program was coded and executed successfully.
  11. 11. Ex.No: 3aDate: DATE COMPARISION USING JAVA SCRIPTAIM: To create a HTML page using java script to find difference between two datesALGORITHM: 1. Write a function using java script to set the date. 2. Write a function using java script to set the month. 3. Write a function using java script to find the difference between two dates. 4. Write another function to display all the details in your page. 5. Use appropriate tags to display the content on your page.s.PROGRAM: datediff.html<HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> function writeOptions(startNumber, endNumber) { var optionCounter; for (optionCounter = startNumber; optionCounter <= endNumber;optionCounter++) { document.write(<OPTION value= + optionCounter + > +optionCounter); } } function writeMonthOptions() { var theMonth; var monthCounter; var theDate = new Date(); for (monthCounter = 0; monthCounter < 12; monthCounter++) { theDate.setMonth(monthCounter); theMonth = theDate.toString(); theMonth = theMonth.substr(4,3); document.write(<OPTION value= + theMonth + > + theMonth);
  12. 12. } } function recalcDateDiff() { var myForm = document.form1; var firstDay =myForm.firstDay.options[myForm.firstDay.selectedIndex].value; var secondDay =myForm.secondDay.options[myForm.secondDay.selectedIndex].value; var firstMonth =myForm.firstMonth.options[myForm.firstMonth.selectedIndex].value; var secondMonth =myForm.secondMonth.options[myForm.secondMonth.selectedIndex].value; var firstYear =myForm.firstYear.options[myForm.firstYear.selectedIndex].value; var secondYear =myForm.secondYear.options[myForm.secondYear.selectedIndex].value; var firstDate = new Date(firstDay + " " + firstMonth + " " + firstYear); var secondDate = new Date(secondDay + " " + secondMonth + " " +secondYear); var daysDiff = (secondDate.valueOf() - firstDate.valueOf()); daysDiff = Math.floor(Math.abs((((daysDiff / 1000) / 60) / 60) / 24)); myForm.txtDays.value = daysDiff; var age=daysDiff/365; myForm.age1.value=Math.floor(age); return true; } function window_onload() { var theForm = document.form1; var nowDate = new Date(); theForm.firstDay.options[nowDate.getDate() - 1].selected = true; theForm.secondDay.options[nowDate.getDate() - 1].selected = true; theForm.firstMonth.options[nowDate.getMonth()].selected = true; theForm.secondMonth.options[nowDate.getMonth()].selected = true; theForm.firstYear.options[nowDate.getFullYear()- 1970].selected = true; theForm.secondYear.options[nowDate.getFullYear() - 1970].selected =true; } </SCRIPT> </HEAD><BODY LANGUAGE="JavaScript" onload="return window_onload()">
  13. 13. <FORM NAME="form1"> <P> Select your Date of Birth<BR> <SELECT NAME="firstDay" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeOptions(1,31); </SCRIPT> </SELECT> <SELECT NAME="firstMonth" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE=JavaScript> writeMonthOptions(); </SCRIPT> </SELECT> <SELECT NAME="firstYear" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeOptions(1970,2010); </SCRIPT> </SELECT> </P> <P> Select End Date<BR> <SELECT NAME="secondDay" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE=JavaScript> writeOptions(1,31); </SCRIPT> </SELECT> <SELECT NAME="secondMonth" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeMonthOptions(); </SCRIPT> </SELECT> <SELECT NAME="secondYear" SIZE="1" onchange="returnrecalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript">
  14. 14. writeOptions(1970,2010); </SCRIPT> </SELECT> </P> Total difference in days: <INPUT TYPE="text" NAME="txtDays" VALUE="0" size="3"> <p>Your Age is: <INPUT TYPE="text" NAME="age1" VALUE="0" size="2"> </p> </FORM></BODY></HTML>
  15. 15. OUTPUT:RESULT: Thus the given program was coded and executed successfully.
  16. 16. Ex.No: 3bDate: FORM VALIDATION USING JAVA SCRIPTAIM: To write a program for form validation using java script.ALGORITHM: 1. Design a page for signup form with rich user interface. 2. Write the java script function to validate all mandatory fields on your web page. 3. Validation should be done after the submit operation. 4. Use appropriate tags to display the contents. 5. Make sure the page is working efficiently.PROGRAM: signup.html<html> <head> <title>Student Registration Form</title> <script type="text/javascript"> <!-- function validate() { if(document.signup.fname.value=="") { alert("Please Enter First Name!"); return false; } if(document.signup.lname.value=="") { alert("Please Enter Last Name!"); return false; } if(document.signup.uname.value=="") { alert("Please Enter User Name!"); return false; } if(document.signup.pword1.value=="") { alert("Please Enter Password!"); return false; }
  17. 17. if(document.signup.pword1.value.length<6) { alert("Please enter min 6 characters!"); return false; } if(document.signup.pword2.value=="") { alert("Please Enter Password again!"); return false; } if(document.signup.pword2.value!=document.signup.pword1.value) { alert("Password is mismatch. Re-enter password!"); return false; } alert("Details Entered Successfully"); display(); } function display() { document.writeln(<h2>+"Details Entered..."+</h2>); document.writeln(<br/><font color="#0066FF">+"First Name:"+</font>+document.signup.fname.value); document.writeln(<br/><font color="#0066FF">+"Last Name:"+</font>+document.signup.lname.value); document.writeln(<br/><font color="#0066FF">+"User Name:"+</font>+document.signup.uname.value); document.writeln(<br/><font color="#0066FF">+"Country: "+</font>+document.signup.country.value); document.writeln(<br/><font color="#0066FF">+"AlternateEmail: "+</font>+document.signup.aemail.value); } --> </script> </head> <body align="center" bgcolor="grey" > <table width="100%" height="100%"> <td colspan="2" width="15%"> </td> <td colspan="1" bgcolor="#FFFFFF" width="70%" height="100%"> <h1 align="center"><font color="#0066FF">SMail</font></h1> <h2 align="center"><font color="#0066FF">New User SignupForm</font></h2>
  18. 18. <form name="signup" onSubmit="return validate()"> <font face="Verdana, Arial, Helvetica, sans-serif" color="#660000"size="2"> <p>&nbsp;&nbsp;*First Name:<input type="text" name="fname"size="20"> &nbsp;&nbsp;*Last Name:<input type="text" name="lname"size="20"> </p> <p style=" border:">&nbsp;&nbsp;*User Name:<input type="text"name="uname" size="20">@smail.com</p> <p style=" border:">&nbsp;&nbsp;*Password :&nbsp;<inputtype="password" name="pword1">(min 6 characters)</p> <p style=" border:">&nbsp;&nbsp;*Confirm Password:<inputtype="password" name="pword2" size="20"></p> <p>&nbsp;&nbsp;Gender : <input type="radio" name="gen" value="male">Male <input type="radio" name="gen" value="female">Female </p> <p>&nbsp;&nbsp;Country: <select name="country"> <option selected>Select Country</option> <option name="country"value="india">India</option> <option name="country"value="russia">Russia</option> <option name="country"value="france">France</option> <option name="country"value="italy">Italy</option> </select> </p> <p>&nbsp;&nbsp;Language Known:<br/> &nbsp;&nbsp;<input type="checkbox" name="lang"value="tamil">Tamil<br/> &nbsp;&nbsp;<input type="checkbox" name="lang"value="english">English<br/> &nbsp;&nbsp;<input type="checkbox" name="lang"value="hindi">Hindi<br/> &nbsp;&nbsp;<input type="checkbox" name="lang"value="Malayalam">Malayalayam<br/> </p> <p style=" border:">&nbsp;&nbsp;Alternate Email:<inputtype="text" name="aemail" size="20"></p> <p align="center"><input type="checkbox" name="agree"value="agree">I agree the terms and conditions</p> <p align="center"><input type="submit" value="Submit"><inputtype="Reset" value="Reset"></p>
  19. 19. </font> </form> </td> <td colspan="2" width="15%"> </td> </table> </body></html>
  20. 20. OUTPUT:RESULT: Thus the given program was coded and executed successfully.
  21. 21. Ex.No:4Date: ONLINE BOOK SHOPPING USING JSP OBJECTSAIM: To write an online book shopping application using JSP objects.ALGORITHM: 1. Create home, login, registration, profile, catalog and order html pages. 2. Create jsp pages which does all business works on the server. 3. Use appropriate database to store the details of the books. 4. Create tables to store login details and books details. 5. Connect the database using odbc.jdbc driver. 6. Make changes in the control settings to enable database on your local machine.PROGRAM: Main.html <html> <body bgcolor=”pink”> <br><br><br><br><br><br> <h1 align=”center”>>U>ONLINE BOOK STORAGE</u></h1><br><br><br> <h2 align=”center”><PRE> <b> Welcome to online book storage. Press LOGIN if you are having id Otherwise press REGISTRATION </b></PRE></h2> <br><br><pre> <div align=”center”><a href=”/tr/login.html”>LOGIN</a> href=”/tr/login.html”>REGISTRATION</a></div></pre> </body></html> Login.html <html> <body bgcolor=”pink”><br><br><br> <form name="myform" method="post" action=/tr1/login.jsp"> <div align="center"><pre> LOGIN ID : <input type="passwors" name="pwd"></pre><br><br> PASSWORD : <input type="password" name="pwd"></pre><br><br> </div> <br><br> <div align="center">
  22. 22. <inputtype="submit"value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"></form></body></html> Reg.html<html><body bgcolor="pink"><br><br><form name="myform" method="post" action="/tr1/reg.jsp"> <div align="center"><pre> NAME :<input type="text" name="name"><br> ADDRESS :<input type="text" name="addr"><br> CONTACT NUMBER : <input type="text" name="phno"><br> LOGIN ID : <input type="text" name="id"><br> PASSWORD : <input type="password" name="pwd"></pre><br><br> </div> <br><br> <div align="center"> <inputtype="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"> </form> </body> </html> Profile.html<html><body bgcolor="pink"><br><br><form name="myform" method="post" action="/tr1/profile.jsp"> <div align="center"><pre> LOGIN ID : <input type="text" name="id"><br> </pre><br><br> </div> <br><br> <div align="center"> <inputtype="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"> </form> </body> </html>
  23. 23. Catalog.html <html> <body bgcolor="pink"><br><br><br> <form method="post" action="/tr1/catalog.jsp"> <div align="center"><pre> BOOK TITLE : <input type="text" name="title"><br> </pre><br><br> </div> <br><br> <div align="center"> <inputtype="submit"value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<inputtype="reset"value="clear " name=”button2”> </form> </body> </html> Order.html <html> <body bgcolor="pink"><br><br><br> <form method="post" action="/tr1/order.jsp"> <div align="center"><pre> LOGIN ID :<input type="text" name="id"><br> PASSWORD : <input type="password" name="pwd"><br> TITLE :<input type="text" name="title"><br> NO. OF BOOKS : <input type="text" name="no"><br> DATE : <input type="text" name="date"><br> CREDIT CARD NUMBER : <input type="password"name="cno"><br></pre><br><br> </div> <br><br> <div align="center"> <input type="submit" value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" name=”button2”> </form> </body> </html> Login.jsp %@page import=”java.sql.*”% %@page import=”java.io.*”% <%
  24. 24. out.println(“<html><body bgcolor=”pink”>”); String id=request.getParameter(“id”); String pwd=request.getParameter(“pwd”); Driver d=new oracle.jdbc.driver.OracleDriver(); DriverManager.registerDriver(d); Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott” ,”tiger”); Statement stmt=con.createStatement(); String sqlstmt=”select id,password from login where id=”+id+” andpassword=”+pwd+””; ResultSet rs=stmt.executeQuery(sqlstmt); int flag=0; while(rs.next()) { flag=1; } if(flag==0) { out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”); out.println(“ <a href=”/tr1/login.html”>press LOGIN to RETRY</a>”); } else { out.println(“VALID LOGIN ID<br><br>”); out.println(“<h3><ul>”); out.println(“<li><ahref=”profile.html”><fontcolor=”black”>USER PROFILE</font></a></li><br><br>”); out.println(“<li><ahref=”catalog.html”><fontcolor=”black”>BOOKS CATALOG</font></a></li><br><br>”); out.println(“<li><ahref=”order.html”><fontcolor=”black”>ORDER CONFIRMATION</font></a></li><br><br>”); out.println(“</ul>”); } out.println(“<body></html>”); %> Reg.jsp %@page import=”java.sql.*”% %@page import=”java.io.*”% <% out.println(“<html><body bgcolor=”pink”>”); String name=request.getParameter(“name”);
  25. 25. String addr=request.getParameter(“addr”); String phno=request.getParameter(“phno”); String id=request.getParameter(“id”); String pwd=request.getParameter(“pwd”); int no=Integer.parseInt(phno); Driver d=new oracle.jdbc.driver.OracleDriver(); DriverManager.registerDriver(d); Connection con= DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement stmt=con.createStatement(); String sqlstmt=”select id from login”; ResultSet rs=stmt.executeQuery(sqlstmt); int flag=0; while(rs.next()){ if(id.equals(rs.getString(1))) { flag=1; }}if(flag==1){ out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID<br><br>”); out.println(“<a href=”/tr1/reg.html”>press REGISTER to RETRY</a>”);}else{ Statement stmt1=con.createStatement (); stmt1.executeUpdate (“insert into login values(“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”); out.println (“YOU DETAILS ARE ENTERED <br><br>”); out.println (“<a href =”/tr1/login.html”>press LOGIN to login</a>”);} out.println (“</body></html>”);%> Profile.jsp <%@page import=”java.sql.*”%> <%@page import=”java.io.*”%> <% out.println (“<html><body bgcolor=”pink”>”); String id=request.getParameter(“id”);
  26. 26. Driver d=new oracle.jdbc.driver.OracleDriver(); DriverManager.regiserDriver(d); Connection con= DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement stmt=con.createStatement (); String sqlstmt=”select * from login where id=”+id+””; ResultSet rs=stmt.executeQuery (sqlstmt); int flag=0; while(rs.next()) { out.println (“<div align=”center”>”); out.println (“NAME :”+rs.getString(1)+”<br>”); out.println (“ADDRESS :”+rs.getString(2)+”<br>”); out.println (“PHONE NO :”+rs.getString(3)+”<br>”); out.println (“</div>”); flag=1;}if(flag==0) { out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a href=”/tr1/profile.html”>press HERE to RETRY </a>”);}out.println (“</body></html>”);%> Catalog.jsp <%@page import=”java.sql.*”%> <%@page import=”java.io.*”%> <% out.println (“<html><body bgcolor=”pink”>”); String title=request.getParameter (“title”); Driver d=new oracle.jdbc.driver.OracleDriver (); DriverManager.regiserDriver (d); Connection con= DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement stmt=con.createStatement (); String sqlstmt=”select * from book where title=”+title+””; ResultSet rs=stmt.executeQuery (sqlstmt); int flag=0; while(rs.next()) { out.println (“<div align=”center”>”);
  27. 27. out.println (“TITLE :”+rs.getString(1)+”<br>”); out.println (“AUTHOR :”+rs.getString(2)+”<br>”); out.println (“VERSION:”+rs.getString(3)+”<br>”); out.println (“PUBLISHER :” +rs.getString(4)+”<br>”); out.println (“COST :” +rs.getString(5)+”<br>”); out.println (“</div>”); flag=1;}if(flag==0) { out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a href=”/tr1/catalog.html”>press HERE to RETRY </a>”);}out.println (“</body></html>”);%> Order.jsp <%@page import=”java.sql.*”%> <%@page import=”java.io.*”%> <% out.println (“<html><body bgcolor=”pink”>”); String id=request.getParameter (“id”); String pwd=request.getParameter (“pwd”); String title=request.getParameter (“title”); String count1=request.getParameter (“no”); String date=request.getParameter (“date”); String cno=request.getParameter (“cno”); int count=Integer.parseInt(count1); Driver d=new oracle.jdbc.driver.OracleDriver (); DriverManager.regiserDriver (d); Connection con= DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement stmt=con.createStatement (); String sqlstmt=”select id, password from login”; ResultSet rs=stmt.executeQuery (sqlstmt); int flag=0,amount,x; while(rs.next()) { if(id.equals(rs.getString(1))&& pwd.equals(rs.getString(2))) { flag=1; }}if(flag==0)
  28. 28. { out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a href=”/tr1/order.html”>press HERE to RETRY </a>”);}else{ Statement stmt2=con.createStatement(); String s=”select cost from book where title=”+title+””; ResultSet rs1=stmt2.executeQuery(s); int flag1=0; while(rs1.next()) { flag1=1; x=Integer.parseInt(rs1.getString(1)); amount=count*x; out.println(“AMOUNT :”+amount+”<br><br><br><br>”); Statement stmt1=con.createStatement (); stmt1.executeUpdate(“insert into details(“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”); out.println (“YOU ORDER HAS TAKEN<br>”);}if(flag1==0){ out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”); out.println(“<a href=”/tr1/order.html”>press HERE to RETRY </a>”); }} out.println (“</body></html>”);%>
  29. 29. OUTPUT:
  30. 30. RESULT: Thus the given program was coded and executed successfully.
  31. 31. Ex.No:5Date: SIMPLE SERVLET PROGRAMAIM: To write a simple servlet program using HTTP in java.ALGORITHM: 1. Create a servlet program using http. 2. Set classpath where servlet-api.jar file resides. 3. Compile the servlet program using javac programname.java 4. Place the class file …Tomcat 5.5webappsROOTWEB-INFclasses folder. 5. modify the web.xml file using your servletClassName. 6. Invoke the class file using http://localhost:8080/servetClassName from your browserPROGRAM: CmsHome.javaimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class mailamHome extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<html>"); pw.println("<head><title>Hello World</title></title>"); pw.println("<body>"); pw.println("<h1>CMS COLLEGE OF ENGINEERING</h1>"); pw.println("<h2>An ISO 9001:2000 Certified Institution</h2>"); pw.println("<h3>Affliated to Anna University</h3>"); pw.println("</body></html>"); }} web.xml<?xml version="1.0" encoding="ISO-8859-1"?><!--<!DOCTYPE web-appPUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"> -->
  32. 32. <web-app><servlet> <servlet-name>Mailam</servlet-name> <servlet-class>mailamHome</servlet-class></servlet><servlet-mapping><servlet-name>Mailam</servlet-name><url-pattern>/mailamHome</url-pattern></servlet-mapping></web-app>
  33. 33. OUTPUT:RESULT: Thus the given program was coded and executed successfully.
  34. 34. Ex.No:06Date: STUDENT INFORMATION SYTEM USING JSP AND SERVLETAIM: To develop the student webpage information using java servlet andJDBC.ALGORITHM : 1. Start the program 2. Create main HTML page for student database maintenance 3. Select option to do the following operation 4. Insertion, search ,delete and modify or update the student recode Main.html<html><body bgcolor=yellow text=red><div align=center><label><h2>Student database maintenance</h2> </label><TABLE><TR><TD><ahref="http://localhost:7001/student/register.html">REGISTER</a></TD></TR><TR><TD><ahref="http://localhost:7001/student/find3">SEARCH</a></TD></TR><TR><TD><a href="http://localhost:7001/student/viewall">VIEW ALL</a></TD></TR><TR><TD><ahref="http://localhost:7001/student/delete2.html">DELETE</a></TD></TR><!--<TR><TD><ahref="http://localhost:7001/student/update">UPDATE</a></TD></TR>--></table></div></body></html> Register.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> registration </TITLE></HEAD><BODY bgcolor=teak text=red><form action="http://localhost:7001/student/register1" method=post><pre>
  35. 35. Enter Id : <input type=text name="id" size=4 ><br>Enter Name : <input type=text name="name" size=20 ><br>Enter Age : <input type=text name="age" size=4 ><br>Enter Branch: <input type=text name="branch" size=10 ><br>Enter Mark1 : <input type=text name="m1" size=4 ><br>Enter Mark2 : <input type=text name="m2" size=4 ><br>Enter Mark3 : <input type=text name="m3" size=4 ><br>Enter Grade : <input type=text name="grade" size=20 ><br>Click : <input type="submit" name="submit" value=register></pre></form></BODY></HTML> Insert.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> registration </TITLE></HEAD><BODY bgcolor=teak text=red><form action="http://localhost:7001/student/insert" method=post><pre><div align=center>Enter Id : <input type=text name="id" size=4 ><br>Enter Name : <input type=text name="name" size=20 ><br>Enter Age : <input type=text name="age" size=4 ><br>Enter Branch: <input type=text name="branch" size=10 ><br>Enter Mark1 : <input type=text name="m1" size=4 ><br>Enter Mark2 : <input type=text name="m2" size=4 ><br>Enter Mark3 : <input type=text name="m3" size=4 ><br>Enter Grade : <input type=text name="grade" size=4 ><br><input type="submit" name="submit" value=register></div></pre></form></BODY></HTML> Delete.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> DELETE STUDENT RECORD </TITLE></HEAD><BODY bgcolor=yellow text=cyan><form action="http://localhost:7001/student/delete2" method=post><pre>Enter the ID :<input type=text name="idno" size=4 ><br>Click :<input type="submit" name=submit value=delete></pre></form>
  36. 36. </BODY></HTML> Second.javaimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.lang.*;public class second extends HttpServlet{public void doGet(HttpServletRequest req,HttpServletResponseres)throws ServletException,IOException{loginform(res,false);}//goGet()private void loginform(HttpServletResponse res,boolean error)throwsServletException,IOException{res.setContentType("text/html");PrintWriter pr=res.getWriter();pr.println("<html><body bgcolor=blue text=red>");pr.println("<div align=center>");if(error){pr.println("<H2>LOGIN FAILED, PLEASE TRYAGAIN!!!</H2>");}pr.println("<form method=post NAME=FORM>");pr.println("<table><TR><TD><label> please enter your nameand password</label></TR></TD>");pr.println("<TR><TD>Username:<input type=textname=username> ");pr.println("<TR><TD>Password:<input type=passwordname=password><br></TR></TD><hr width=100%></TR></TD>");pr.println("<TR><TD>Press:<input type=submit name=submitvalue=Continue></TR></TD>");pr.println("<TR><TD>clear:<input type=reset name =resetvalue=Clear></TR></TD></TABLE>");pr.println("</form></div></body></html>");}//loginform()public void doPost(HttpServletRequest req,HttpServletResponseres)throws ServletException,IOException{String name=req.getParameter("username");String pass=req.getParameter("password");
  37. 37. if(logindb(name,pass)){RequestDispatcher rd=req.getRequestDispatcher("/main.html");rd.forward(req,res);}else{loginform(res,true);}}//doPost()boolean logindb(String name, String pass){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connectioncon=DriverManager.getConnection("jdbc:odbc:logindb");Statement s=con.createStatement();String sql="select * from stu where username= " + name+ " AND password= " + pass + " ";ResultSet rs=s.executeQuery(sql);if(rs.next()){return true;}con.close();}catch(SQLException s){s.printStackTrace();}catch(Exception e){e.printStackTrace();}return false;}//login()}; Register1.java/* INSERTING THE DATA */import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;
  38. 38. import java.lang.*;public class register1 extends HttpServlet{public void doPost(HttpServletRequest req,HttpServletResponseres)throws ServletException, IOException{try{res.setContentType("Text/html");PrintWriter pr=res.getWriter();int id=Integer.parseInt(req.getParameter("id"));String name=req.getParameter("name");int age=Integer.parseInt(req.getParameter("age"));String branch=req.getParameter("branch");int m1=Integer.parseInt(req.getParameter("m1"));int m2=Integer.parseInt(req.getParameter("m2"));int m3=Integer.parseInt(req.getParameter("m3"));String grade=req.getParameter("grade");pr.println("<html><body bgcolor=yellow text=red><divalign=center>");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:ss");//pr.println("student information are successfully registered");//pr.println("<ahref=http://localhost:7001/student/main.html>goto main page</a>");PreparedStatement pst=con.prepareStatement("Insert intostudata values(?,?,?,?,?,?,?,?) ");pst.setInt(1,id);pst.setString(2,name);pst.setInt(3,age);pst.setString(4,branch);pst.setInt(5,m1);pst.setInt(6,m2);pst.setInt(7,m3);pst.setString(8,grade);pst.executeQuery();pr.println("student information are successfully registered");pr.println("<ahref=http://localhost:7001/student/main.html>goto main page</a>");pr.println("</html></body>");con.commit();}catch(SQLException e){System.out.println(e.getMessage());}
  39. 39. catch(Exception e){e.printStackTrace();}}}; Insert.javaimport javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;import java.lang.*;public class register extends HttpServlet{public void doPost(HttpServletRequest req,HttpServletResponseres)throws ServletException, IOException{try{res.setContentType("Text/html");PrintWriter pr=res.getWriter();int id=Integer.parseInt(req.getParameter("id"));String name=req.getParameter("name");int age=Integer.parseInt(req.getParameter("age"));String branch=req.getParameter("branch");int m1=Integer.parseInt(req.getParameter("m1"));int m2=Integer.parseInt(req.getParameter("m2"));int m3=Integer.parseInt(req.getParameter("m3"));String grade=req.getParameter("grade");pr.println("<html><body bgcolor=yellow text=red><divalign=center>");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:ss");// pr.println("Get connection");PreparedStatement pst=con.prepareStatement("Insert intostudata values(?,?,?,?,?,?,?,?) ");pst.setInt(1,id);pst.setString(2,name);pst.setInt(3,age);pst.setString(4,branch);pst.setInt(5,m1);pst.setInt(6,m2);pst.setInt(7,m3);pst.setString(8,grade);pst.executeQuery();
  40. 40. con.commit();pr.println("student information are successfully registered");pr.println("<ahref=http://localhost:7001/student/main.html>goto main page</a>");pr.println("</html></body>");con.close();}catch(SQLException e){System.out.println(e.getMessage());}catch(Exception e){e.printStackTrace();}}}; Find3.Java/* SEARCH THE PARTICULAR RECORD */import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;import java.lang.*;public class find3 extends HttpServlet{public void doGet(HttpServletRequest req,HttpServletResponse res)throwsServletException, IOException{res.setContentType("Text/html");PrintWriter pr=res.getWriter();pr.println("<html><body bgcolor=black text=green><divalign=center>");pr.println("<form action=http://localhost:7001/student/find3method=post name=form1>");pr.println("<h4>Enter the student ID:</h4><input type=text name=id>");pr.println("<h4>click:</h4><input type=submit name=submitvalue=search>");pr.println("</form></div></body></html>");}public void doPost(HttpServletRequest req,HttpServletResponseres)throws ServletException, IOException{
  41. 41. try{res.setContentType("Text/html");PrintWriter pr=res.getWriter();String id =req.getParameter("id");int idno=Integer.parseInt(id);pr.println("<html><body bgcolor=black text=green><divalign=center>");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:ss");//PreparedStatement pst=con.prepareStatement("select * from studata whereID= " + idno + " ");PreparedStatement pst=con.prepareStatement("select * from studata whereID= ? ");pst.setInt(1,idno);ResultSet r=pst.executeQuery();while(r.next()){pr.println(r.getInt(1)+"t"+r.getString(2)+"t"+r.getInt(3)+"t"+r.getString(4)+"t"+r.getInt(5)+"t"+r.getInt(6)+"t"+r.getInt(7)+"t"+r.getString(8));pr.println("<br>");}pr.println("<a href=http://localhost:7001/student/main.html>goto mainpage</a>");pr.println("</html></body>");}catch(SQLException e){System.out.println(e.getMessage());}catch(Exception e){e.printStackTrace();}}}; Delete2.javaimport javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;import java.lang.*;public class delete2 extends HttpServlet{
  42. 42. public void doPost(HttpServletRequest req,HttpServletResponseres)throws ServletException, IOException{try{res.setContentType("Text/html");PrintWriter pr=res.getWriter();pr.println("<html><body bgcolor=black text=yellow>");String idno=req.getParameter("idno");int id=Integer.parseInt(idno);Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:ss");pr.println("get connected");//PreparedStatement pst=con.prepareStatement("Delete from studatawhere ID= " + id + " ");PreparedStatement pst=con.prepareStatement("Delete from studatawhere ID= ? ");pst.setInt(1,id);pst.executeUpdate();pr.println("<h2>student record is successfully deleted");pr.println("<a href=http://localhost:7001/student/main.html>goto mainpage</a>");pr.println("</html></body>");con.commit();}catch(SQLException e){System.out.println(e.getMessage());}catch(Exception e){e.printStackTrace();}}};
  43. 43. Output:Studenttable.
  44. 44. RESULT : Thus student information java script program is successfully completed.
  45. 45. Ex.No:07Date: SIMPLE XML DOCUMENT FOR CD SHOPAIM: To create a XML document for the CD-Store.ALGORITHM: 1. Create the XML document using <?xml version="1.0" encoding="ISO-8859-1"? > tag as the initial tab. 2. Create another CSS document which displays the xml document details into HTML format on the browser. 3. Give appropriate style in the CSS document. 4. Invoke xml file from your browser.PROGRAM: cd_catalog_css.xml<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited by XMLSpy® --><?xml-stylesheet type="text/css" href="cd_catalog.css"?><CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1982</YEAR>
  46. 46. </CD><CD> <TITLE>Still got the blues</TITLE> <ARTIST>Gary Moore</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin records</COMPANY> <PRICE>10.20</PRICE> <YEAR>1990</YEAR></CD><CD> <TITLE>Eros</TITLE> <ARTIST>Eros Ramazzotti</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>BMG</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR></CD><CD> <TITLE>One night only</TITLE> <ARTIST>Bee Gees</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.90</PRICE> <YEAR>1998</YEAR></CD><CD> <TITLE>Sylvias Mother</TITLE> <ARTIST>Dr.Hook</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS</COMPANY> <PRICE>8.10</PRICE> <YEAR>1973</YEAR></CD><CD> <TITLE>Maggie May</TITLE> <ARTIST>Rod Stewart</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Pickwick</COMPANY> <PRICE>8.50</PRICE> <YEAR>1990</YEAR></CD><CD> <TITLE>Romanza</TITLE> <ARTIST>Andrea Bocelli</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Polydor</COMPANY>
  47. 47. <PRICE>10.80</PRICE> <YEAR>1996</YEAR></CD><CD> <TITLE>When a man loves a woman</TITLE> <ARTIST>Percy Sledge</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>8.70</PRICE> <YEAR>1987</YEAR></CD><CD> <TITLE>Black angel</TITLE> <ARTIST>Savage Rose</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Mega</COMPANY> <PRICE>10.90</PRICE> <YEAR>1995</YEAR></CD><CD> <TITLE>1999 Grammy Nominees</TITLE> <ARTIST>Many</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Grammy</COMPANY> <PRICE>10.20</PRICE> <YEAR>1999</YEAR></CD><CD> <TITLE>For the good times</TITLE> <ARTIST>Kenny Rogers</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Mucik Master</COMPANY> <PRICE>8.70</PRICE> <YEAR>1995</YEAR></CD><CD> <TITLE>Big Willie style</TITLE> <ARTIST>Will Smith</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR></CD><CD> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST>
  48. 48. <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>8.20</PRICE> <YEAR>1971</YEAR></CD><CD> <TITLE>Soulsville</TITLE> <ARTIST>Jorn Hoel</ARTIST> <COUNTRY>Norway</COUNTRY> <COMPANY>WEA</COMPANY> <PRICE>7.90</PRICE> <YEAR>1996</YEAR></CD><CD> <TITLE>The very best of</TITLE> <ARTIST>Cat Stevens</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Island</COMPANY> <PRICE>8.90</PRICE> <YEAR>1990</YEAR></CD><CD> <TITLE>Stop</TITLE> <ARTIST>Sam Brown</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>A and M</COMPANY> <PRICE>8.90</PRICE> <YEAR>1988</YEAR></CD><CD> <TITLE>Bridge of Spies</TITLE> <ARTIST>T`Pau</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Siren</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR></CD><CD> <TITLE>Private Dancer</TITLE> <ARTIST>Tina Turner</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Capitol</COMPANY> <PRICE>8.90</PRICE> <YEAR>1983</YEAR></CD><CD>
  49. 49. <TITLE>Midt om natten</TITLE> <ARTIST>Kim Larsen</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Medley</COMPANY> <PRICE>7.80</PRICE> <YEAR>1983</YEAR></CD><CD> <TITLE>Pavarotti Gala Concert</TITLE> <ARTIST>Luciano Pavarotti</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>DECCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1991</YEAR></CD><CD> <TITLE>The dock of the bay</TITLE> <ARTIST>Otis Redding</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR></CD><CD> <TITLE>Picture book</TITLE> <ARTIST>Simply Red</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Elektra</COMPANY> <PRICE>7.20</PRICE> <YEAR>1985</YEAR></CD><CD> <TITLE>Red</TITLE> <ARTIST>The Communards</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>London</COMPANY> <PRICE>7.80</PRICE> <YEAR>1987</YEAR></CD><CD> <TITLE>Unchain my heart</TITLE> <ARTIST>Joe Cocker</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> <PRICE>8.20</PRICE> <YEAR>1987</YEAR>
  50. 50. </CD></CATALOG> cd_catalog.css<style>CATALOG{ background-color: #ffffff; width: 100%;}CD{ display: block; margin-bottom: 30pt; margin-left: 0;}TITLE{ color: #FF0000; font-size: 20pt;}ARTIST{ color: #0000FF; font-size: 20pt;}COUNTRY,PRICE,YEAR,COMPANY{ display: block; color: #000000; margin-left: 20pt;}</style>
  51. 51. OUTPUT:RESULT: Thus the given program was coded and executed successfully.
  52. 52. Ex.No:08Date: SIMPLE XML DOCUMENT WITH DTDAIM: To write a DTD for a domain specific XML document to validate the XML file.ALGORITHM: 1. Start the program 2. Open an XML file as note.xml, to create detail using 3. Various xml attribute list 4. Using user defined tags, we can create message. 5. Using an external and internaldtd,we create elementlist as #PCDATA for retrieve the datafield 6. Using attribute declaration ,use to retrieve the datafield as more than one time 7. Execute the programPROGRAM: note.xml<?xml version="1.0" ?><!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>]><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><message>Dont forget me this weekend!</message></note> dom.xml<html><body><h1>Mailam Engineering Collge</h1><p><b>To:</b> <span id="to"></span><br /><b>From:</b> <span id="from"></span><br /><b>Message:</b> <span id="message"></span></p><script type="text/javascript">
  53. 53. if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest() }else { xhttp=new ActiveXObject("Microsoft.XMLHTTP") }xhttp.open("GET","note.xml",false);xhttp.send("");xmlDoc=xhttp.responseXML;document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;</script></body></html>
  54. 54. OUTPUT:
  55. 55. RESULT: Thus the given program was coded and executed successfully.
  56. 56. Ex.No:09Date: PARSING AN XML DOCUMENT USING DOM AND SAX PARSERS.AIM: To Parsing an XML document using DOM and SAX Parsers.ALGORITHM :Using Dom: 1. Get a document builder using document builder factory and parse the xml file to create a DOM object 2. Get a list of employee elements from the DOM 3. For each employee element get the id, name, age and type. Create an employee value object and add it to the list. 4. At the end iterate through the list and print the employees to verify we parsed it right.Using Sax: 1. Create a Sax parser and parse the xml 2. In the event handler create the employee object 3. Print out the dataPROGRAM: employees.xml<?xml version="1.0" encoding="UTF-8"?><Personnel><Employee type="permanent"><Name>Seagull</Name><Id>3674</Id><Age>34</Age></Employee><Employee type="contract"><Name>Robin</Name><Id>3675</Id><Age>25</Age></Employee><Employee type="permanent"><Name>Crow</Name><Id>3676</Id><Age>28</Age></Employee></Personnel>Using DOMDomParserExample.java
  57. 57. a) Getting a document builderprivate void parseXmlFile(){DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();try {DocumentBuilder db = dbf.newDocumentBuilder();XML filedom = db.parse("employees.xml");}catch(ParserConfigurationException pce) {pce.printStackTrace();}catch(SAXException se) {se.printStackTrace();}catch(IOException ioe) {ioe.printStackTrace();}}b) Get a list of employee elementsGet the rootElement from the DOM object.From the root element get allemployee elements. Iterate through each employee element to load the data.private void parseDocument(){Element docEle = dom.getDocumentElement();NodeList nl = docEle.getElementsByTagName("Employee");if(nl != null && nl.getLength() > 0) {for(int i = 0 ; i < nl.getLength();i++) {Element el = (Element)nl.item(i);Employee e = getEmployee(el);myEmpls.add(e);}}}c) Reading in data from each employee.private Employee getEmployee(Element empEl) {String name = getTextValue(empEl,"Name");int id = getIntValue(empEl,"Id");int age = getIntValue(empEl,"Age");String type = empEl.getAttribute("type");Employee e = new Employee(name,id,age,type);return e;}private String getTextValue(Element ele, String tagName) {String textVal = null;NodeList nl = ele.getElementsByTagName(tagName);
  58. 58. if(nl != null && nl.getLength() > 0) {Element el = (Element)nl.item(0);textVal = el.getFirstChild().getNodeValue();}return textVal;}private int getIntValue(Element ele, String tagName) {return Integer.parseInt(getTextValue(ele,tagName));}d) Iterating and printing.private void printData(){System.out.println("No of Employees " + myEmpls.size() +".");Iterator it = myEmpls.iterator();while(it.hasNext()) {System.out.println(it.next().toString());}}Using Sax:SAXParserExample.java a) Create a Sax Parser and parse the xmlprivate void parseDocument() {SAXParserFactory spf = SAXParserFactory.newInstance();try {SAXParser sp = spf.newSAXParser();sp.parse("employees.xml", this);}catch(SAXException se) {se.printStackTrace();}catch(ParserConfigurationException pce) {pce.printStackTrace();}catch (IOException ie) {ie.printStackTrace();}}b) In the event handlers create the Employee object and call the corresponding settermethods.public void startElement(String uri, String localName, StringqName,Attributes attributes) throws SAXException{tempVal = "";if(qName.equalsIgnoreCase("Employee"))
  59. 59. {tempEmp = new Employee();tempEmp.setType(attributes.getValue("type"));}}public void characters(char[] ch, int start, int length) throwsSAXException {tempVal = new String(ch,start,length);}public void endElement(String uri, String localName,String qName) throws SAXException {if(qName.equalsIgnoreCase("Employee")){myEmpls.add(tempEmp);}else if (qName.equalsIgnoreCase("Name")) {tempEmp.setName(tempVal);}else if (qName.equalsIgnoreCase("Id")){tempEmp.setId(Integer.parseInt(tempVal));}else if (qName.equalsIgnoreCase("Age")){tempEmp.setAge(Integer.parseInt(tempVal));}}c) Iterating and printing.private void printData(){System.out.println("No of Employees " + myEmpls.size() +".");Iterator it = myEmpls.iterator();while(it.hasNext()) {System.out.println(it.next().toString());}}
  60. 60. OUTPUT:Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34.Employee Details - Name:Robin, Type:contract, Id:3675, Age:25.Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28.RESULT: Thus the Parsing an XML document using DOM and SAX Parsers is been doneand executed successfully.
  61. 61. Ex.No:10Date: SAMPLE WEB APPLICATION DEVELOPMENT IN THE OPEN SOURCE ENVIRONMENT WITH DATABASE ACCESSAIM: To create Sample web application development in the open sourceenvironment.ALGORITHM : 1. start the program 2. Inside the asp definiton tag include the html contents 3. include the code for the database connectivity using the ado object 4. select all the datas form the student table 5. Traverse all the tuples in the table 6. Print the datas 7. close the connection 8. stop the programPROGRAM: access.asp<% Option Explicit %><html><% DIM nameset con=Server.CreateObject("ADODB.Connection">con.open "dsn=cse;"set rs=Server.Createobject("ADODB.RecordSet")set rs=con.Execute("select * from student where name="&name&")%><table border="," width="50"%><% while NOT rs.EOF %><tr><% for t=0 to 6 %><td><% Response.write(rs(i)) %><% NEXT %></td></tr><% Move Next wend %></table><%con.close%></html> stuaccess.html<html><form action="access.asp" method="post">Name<input type="text" name="Name"><br><br><input type="submit"><input type="reset">
  62. 62. </form></html>OUTPUT:RESULT : Thus the Sample web application development in the open source nvironmenthas been executed successfully executed.

×