WT Lab
WT Lab
WT Lab
To design college web page using basic Html Tags ALGORITHM:STEP 1: Start the process. STEP 2: Create HTML files with required tags STEP 3: Use frames to separate the window STEP 4: Link the files using the anchor tag STEP 5: Create Tables to organize the college information STEP 6: Place the Image in the created website STEP 7: Place the required data and fields in the created website STEP 8: Stop the process.
PROGRAM:main.html <HTML> <HEAD><title>WeLcome to Paavai college of Engineering</title> </HEAD> <FRAMESET ROWS="30%,*" scrolling="NO"> <FRAME SRC="row1.html" NAME="TOP"/> <FRAMESET COLS="25%,*"> <FRAME SRC="column1.html" NAME="LEFT"/> <FRAME SRC="ugcourse.html" NAME="RIGHT"/> </FRAMESET> </FRAMESET> </HTML> row1.html <HTML> <HEAD> </HEAD> <body bgcolor='yellow'> <p><center> <H1> PAAVAI COLLEGE OF ENGINEERING</H1></center> </p> <p> <center><H2>AFFLIATED TO ANNA UNIVERSITY, CHENNAI </H2> </center> </BODY> </HTML> column1.html <html> <head>
<title>welcome to PAAVAI</title> </head> <body> <a href="ugcourse.html" target="RIGHT">UG COURSES</a><br><br> <a href="pgcourse.html" target="RIGHT">PG COURSES</a><br><br> <a href="library.html" target="RIGHT">LIBRARY FACILITIES</a><br><br> <a href="aboutus.html" target="RIGHT">ABOUT US</a> </body> </html> aboutus.html <HTML> <HEAD> </HEAD> <BODY> <FONT COLOR="violet"> <ol type='I'> <li><font size=5>College started in 1998 <li><font size=5>Placed at Coimbatore <li><font size=5>Internet facility and WIFI Campus <li><font size=5>Hostel Facilities available for both gender <li><font size=5>Placement -on campus and off campus </ol> </FONT> </body> </html> ugcourse.html <HTML> <HEAD> </HEAD>
<BODY> <pre> Our College have the following UG level courses <P> <ul> <li>B.E(CSE) <li>B.TECH(IT) <li>B.E(MECH) <li>B.E(ECE) <li>B.TECH(TEXT) <li>B.E(EEE) </ul> </pre>
</BODY> </HTML> pgcourse.html <HTML> <BODY> <pre> Our college have the following PG level COURSES <ul> <li>M.E(CSE) <li>M.E(Comm Sys) <li>MBA <li>MCA </ul> </pre> </BODY> </HTML> library.html <HTML>
<HEAD> </HEAD> <BODY BGCOLOR=white text=green> <table border="1"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>1.Main library</td> <td>It have many books for all 50,000</td> </tr> <tr> <td>2.digital library</td> <td>Seperate Internet LAB Available</td> </tr> <tr> <td>3.journals and paper section Library</td> <td> No.of Jurnals :569, No.of Projects:2000, All tamil and English Newspapers are available</td> </tr> </table> </BODY> </HTML> department subjects No.of books=
OUTPUT:
RESULT The web page has been successfully designed and the output was verified
To create a HTML page using internal and external CSS. Algorithm: 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> <title>Internal CSS Example Page</title> <link rel="stylesheet" type="text/css" href="styl.css" /> <style> p { font-family:"Times New Roman",Times,serif; font-size:30px; } </style> </head> <body> <h1>Anna University of Technology Chennai</h1> <p>An ISO 9001:2008 Certified Insitution</p> </body> </html> styl.css head { } body { background-color:#d0e4fe;
} h1 { color:orange; text-align:center; }
OUTPUT:
Result: Thus the given program was coded and executed successfully.
10
To create a HTML page using java script to find difference between two dates. Algorithm: 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 pages
11
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++) {
12
theDate.setMonth(monthCounter); theMonth = theDate.toString(); theMonth = theMonth.substr(4,3); document.write('<OPTION value=' + theMonth + '>' + theMonth); } } 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);
13
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>
14
</HEAD> <BODY LANGUAGE="JavaScript" onload="return window_onload()"> <FORM NAME="form1"> <P> Select your Date of Birth<BR> <SELECT NAME="firstDay" SIZE="1" onchange="return recalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeOptions(1,31); </SCRIPT> </SELECT> <SELECT NAME="firstMonth" SIZE= "1" onchange="return recalcDateDiff()"> <SCRIPT LANGUAGE=JavaScript> writeMonthOptions(); </SCRIPT> </SELECT> <SELECT NAME="firstYear" SIZE="1" onchange= "return recalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeOptions(1970,2010); </SCRIPT> </SELECT>
15
</P> <P> Select End Date<BR> <SELECT NAME="secondDay" SIZE="1" onchange= "return recalcDateDiff()"> <SCRIPT LANGUAGE=JavaScript> writeOptions(1,31); </SCRIPT> </SELECT> <SELECT NAME="secondMonth" SIZE= "1" onchange="return recalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeMonthOptions(); </SCRIPT> </SELECT> <SELECT NAME="secondYear" SIZE="1" onchange= "return recalcDateDiff()"> <SCRIPT LANGUAGE="JavaScript"> writeOptions(1970,2010); </SCRIPT> </SELECT> </P>
16
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>
17
OUTPUT:
RESULT: Thus the given program was coded and executed successfully.
18
To design a webpage to validate a form 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.
19
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=="") {
20
alert("Please Enter User Name!"); return false; } if(document.signup.pword1.value=="") { alert("Please Enter Password!"); return false; } 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!");
21
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">'+"Alternate Email: "+'</font>'+document.signup.aemail.value); } --> </script>
22
</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 Signup Form </font></h2> <form name="signup" onSubmit="return validate()"> <font size="2"> <p> *First size="20"> *Last Name:<input type="text" name="lname" size="20"> </p> <p style=" border:"> *User Name:<input type="text" name="uname" size="20">@smail.com</p> <p style=" border:"> *Password : <input type="password" name="pword1">(min 6 characters)</p> <p style=" border:"> *Confirm Password:<input type="password" name="pword2" size="20"></p> Name:<input type="text" name="fname" face="Verdana, Arial, Helvetica, sans-serif" color="#660000"
23
<p> Gender : <input type="radio" name="gen" value="male">Male <input type="radio" name="gen" value="female">Female </p> <p> 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> Language Known:<br/> <input value="tamil">Tamil<br/> <input type="checkbox" name="lang" value="english">English <br/> <input value="hindi">Hindi<br/> <input type="checkbox" name="lang" value="Malayalam">Malayalayam<br/> type="checkbox" name="lang" type="checkbox" name="lang"
24
</p> <p style=" border :"> Alternate Email:<input type="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"><input type="Reset" value="Reset"></p> </font> </form> </td> <td colspan="2" width="15%"> </td> </table> </body> </html>
25
OUTPUT:
RESULT: Thus the given program was coded and executed successfully.
26
To write an online book shopping application using JSP objects. Algorithm: 1. Create home, login, registration, profile, catalog and order html pages. 2. Create a jsp page 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.
27
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>
28
PASSWORD : <input type="password" name="pwd"></pre><br><br> </div> <br><br> <div align="center"> <inputtype="submit"value="ok" onClick="validate()"> <input 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> type="reset"
ADDRESS :<input type="text" name="addr"><br> CONTACT NUMBER : <input type="text" name="phno"><br> LOGIN ID : <input type="text" name="id"><br>
29
<div align="center"> <inputtype="submit"value="ok" onClick="validate()">()"> <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()">()"> <input type="reset" value="clear"> </form> </body> </html>
30
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> <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>
31
PASSWORD TITLE
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> <input type="reset" value="clear" name=button2> </form> </body> </html> Login.jsp: %@page import=java.sql.*% %@page import=java.io.*% <% out.println(<html><body bgcolor=\pink\>);
32
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+ and password=+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( RETRY</a>); } else <a href=\/tr1/login.html\>press LOGIN to
33
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); String addr=request.getParameter(addr);
34
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) {
35
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); Driver d=new oracle.jdbc.driver.OracleDriver();
36
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>); }
37
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\>); out.println (TITLE :+rs.getString(1)+<br>);
38
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);
39
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) {
40
out.println(SORRY INVALID ID TRY AGAIN ID <br><br>); out.println(<a </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>); } href=\/tr1/order.html\>press HERE to RETRY
41
if(flag1==0) { out.println(SORRY INVALID BOOK TRY AGAIN <br><br>); out.println(<a </a>); } } out.println (</body></html>);%> href=\/tr1/order.html\>press HERE to RETRY
42
OUTPUT:
43
44
Result: Thus the given program was coded and executed successfully.
45
To create a servlet program and check the script validation. ALGORITHM: Step 1: Start the program. Step 2: Get the context text at Servlet at text html. Step 3: Get the response from the user by entering the username field. Step 4: Get the response from the user by entering the password field. Step 5: If the username and password are correct, then the user is authenticated and can enter into web page. Step 6: Execute the program in Internet Explorer. Step 7: Stop the program
46
PROGRAM: HTML Code : <HTMl> <HEAD><CENTER></CENTER></HEAD> <CENTER> <body bgcolor="green"> <form action="http://localhost:7001/parthi_servlet/servlet1" method="get"> <h1>USERNAME AND PASSWORD></h1> <TABLE > <TR> <TD>USERNAME<INPUT TYPE="TEXT" name="username"></TD></TR> <TR> <TD> PASSWORD<INPUT TYPE="password" name="password"></TD></TR> <TR> <TD><INPUT TYPE="submit" VALUE="SUBMIT" NAME=SUB></TD> <TD><INPUT TYPE="reset" VALUE="CLEAR" NAME=CLA></TD> </TR> </TABLE></CENTER> </form> </body> </HTML>
47
import javax.servlet.*; import javax.servlet.http.*; public class servlet1 extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { res.setContentType("text/html"); PrintWriter pw=res.getWriter(); String admin=req.getParameter("username"); String pass=req.getParameter("password"); pw.println(admin); pw.println(pass); if((admin.equals("admin2010")) && (pass.equals("abc123"))) { pw.println("Authorized user"); } else { pw.println("not an Authorized user"); } } }
48
Output:
Result: Thus the given program was coded and executed successfully.
49
To create an online application using database access. Algorithm: 1. Create an ASP page which get details from the user. 2. Create a database connection using ASP code. 3. Compare the details of the user with the database. 4. Get the amount from the user from payment gateway. 5. Deliver the products the user to his/her address.
50
Program: send.asp <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta 1252"> <title>New Page 1</title> <style> <!-.lnk --> </style> </head> <body> <% dim view view = request.querystring("view") if view = "" then { text-decoration: none; color: #FFFFFF; font-weight: bold } http-equiv="Content-Type" content="text/html; charset=windows-
51
view = "view1.xsl" end if %> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" height="100"> <tr> <td width="33%" colspan="2" height="81"> <h1>XML Database</h1> </td> <td width="67%" colspan="2" height="81"> </td> </tr> <tr> <td width="16%" align="center" dir="ltr" bgcolor="#336699" height="19"> <a class="lnk" href="send.asp?view=view1.xsl">View1</a> </td> <td width="17%" bgcolor="#336699" align="center" dir="ltr" height="19"> <a class="lnk" href="send.asp?view=view2.xsl">View2</a></td> <td width="17%" bgcolor="#336699" align="center"
height="19"> </td>
52
<% dim xmlhttp,xmlDom,xsldom,Query set xmlhttp=createobject("MSXML2.XMLHTTP") set xmlDom=createobject("MSXML2.domdocument") set xslDom=createobject("MSXML2.domdocument") xmldom.async=false xsldom.async=false query = "<main><sql>select * from product</sql></main>" xmlhttp.Open false xmlhttp.send query if xmlhttp.status <> 200 then response.write "Error !!!" end if xmldom.load xmlhttp.responseXML xsldom.load server.mappath(".")+"/"+view response.write XMLDom.transformNode(XSLDom) "POST","http://localhost/xmlDatabase/datasource.asp",
53
%> <% set xmlhttp = nothing set xmldom= nothing set xsldom = nothing %> </body> </html> datasource.asp <% Option Explicit %> <%Response.ContentType = "text/xml"%><?xml version="1.0"?> <% dim xmlDom dim Conn,rs,fld,query set xmlDom=createobject("MSXML2.domdocument") Set Conn = server.CreateObject("adodb.connection") set rs = server.createobject("adodb.recordset") xmldom.load request query = xmldom.documentElement.childNodes(0).text Conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath(".")+"\database.mdb;Persist Security Info=False"
54
rs.open query,conn,3,1 %> <recordset total="<%=rs.recordcount%>"> <head> <%for each fld in rs.fields%> <field name="<%=fld.name%>"/> <%next%> </head> <rows> <%do until rs.eof%> <row> <%for each fld in rs.fields%> <col><%=fld.value%></col> <%next%> </row> <%rs.movenext%> <%loop%> </rows> </recordset> <% rs.close
55
set xmldom = nothing %> View1.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <table align = "center" border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber2"
cellpadding="0"> <xsl:for-each select="recordset/rows/row"> <TR> <xsl:apply-templates select="col"/> </TR> </xsl:for-each> </table> </xsl:template> <xsl:template match="col">
56
<TD><xsl:value-of select="."/></TD> </xsl:template> </xsl:stylesheet> View2.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1"> <tr> <xsl:apply-templates select="recordset/head/field"/> </tr> <xsl:for-each select="recordset/rows/row"> <TR> <xsl:apply-templates select="col"/> </TR> </xsl:for-each> </table> </xsl:template> <xsl:template match="col">
57
<TD><xsl:value-of select="."/></TD> </xsl:template> <xsl:template match="recordset/head/field"> <td bgcolor="#C0C0C0"><xsl:value-of select="./@name"/></td> </xsl:template> </xsl:stylesheet>
Output:
58
Result: Thus the given program was coded and executed successfully.
59
To creation of XML document for a specific domain ALGORITHM: Step 1: start the program Step 2: Using Onclick(),validate the student details as entered. Step 3: In XML file,we use styles for structure the program as
#PCDATA(datafield) Step 4: Using various HTML tags and attribute,we design the web page. Step 5: Using various XML attribute list and entity list to retrieve the information of student. Step 6: Using processing instructions which we required to describe the data. Step 7: Using note.xmlas xmlid to connect with html file.Execute the program. Step 8: Stop the program.
60
PROGRAM: Student.html: <HTML> <HEAD> <SCRIPT> function prev_onclick() { std.previousPage() } function next_onclick() { std.nextPage() } </SCRIPT> </HEAD> <BODY> <xml id="note" src="note.xml"></xml> <table id="std" dataSrc="#note" datapagesize="1" border="1"> <thead> <tr><th>REGNO</th><th>NAME</th><th>COURSE</th><TH>SEM</th> </tr>
61
</thead> <tbody> <tr><td><span datafld="REGNO"></span></td> <td><span datafld="NAME"></span></td> <td><span datafld="COURSE"></span></td> <td><span datafld="SEM"></span></td> </tr> </tbody> </table> <INPUT TYPE="BUTTON" VALUE="NEXT" ONCLICK="next_onclick()"> <INPUT TYPE="BUTTON" VALUE="PREVIOUS" ONCLICK="prev_onclick()"> </BODY> </HTML> note.xml: <?xml version="1.0"?> <note> <STUDENT> <REGNO>0001</REGNO> <NAME>SURESH.V</NAME> <COURSE>M.E CSE</COURSE> <SEM>II</SEM>
62
63
OUTPUT:
Result: Thus the given program was coded and executed successfully.
64
WRITING DTD OR XML SCHEMA FOR THE DOMAIN SPECIFIC XML DOCUMENT
To write a program for DTD and XML schema for the domain specific XML document. ALGORITHM: Step1: Start the program Step2: Open an XML file as Letter.xml, to create detail of person using various xml attribute list Step3: Using user defined tags, we can create details of person using name, pincode, address, ph.no, etc.. Step4: Open DTD file as letter . dtd Step5: Using an external and internaldtd,we create elementlist as #PCDATA for retrieve the datafield Step6: Using attribute declaration ,use to retrieve the datafield as more than one time Step7: Execute the program
65
PROGRAM: Letter.xml: <?xml version="1.0"?> <letter> <contact type="sender"> <name>aaaa</name> <address>dfdsgdsgdsfvg</address> <city>chennai</city> <state>tamilnadu</state> <zip>600089</zip> <phone>044-23456789</phone> <flag gender="F"/> </contact> <contact type="receiver"> <name>bbbb</name> <address1>dfdsgdsgdsfvg</address1> <address2>fvgefgffdg</address2> <city>chennai</city> <state>tamilnadu</state> <zip>600089</zip> <phone>044-23456789</phone>
66
<flag gender="F"/> </contact> <salutation>Dear Sir: </salutation> <paragraph>It is our privillege .........</paragraph> <closing>Sincerely</closing> <signature>Ms.aaaaa</signature> </letter> Letter.dtd: <!element letter(contact+, salutation, paragraph+, closing, signature)> <element contact(name, address1, address2, city, state, zip, phone, flag)> <!attlist contacttype CDATA #implied> <!element address1(#PCDATA)> <!element address2(#PCDATA)> <!element city(#PCDATA)> <!element state(#PCDATA)> <!element zip(#PCDATA)> <!element phone(#PCDATA)> <!element flag EMPTY> <!attlist flag gender(M/F)"M"> <!element salutation(#pcdata)> <!element closing (#pcdata)> <!element paragraph (#pcdata)> <!element signature (#pcdata)>
67
OUTPUT:
RESULT: Thus the given program was coded and executed successfully.
68
To Parsing an XML document using DOM and SAX Parsers. ALGORITHM: Using DOM: Step 1: Get a document builder using document builder factory and parse the xml file to create a DOM object Step 2: Get a list of employee elements from the DOM Step 3: For each employee element get the id, name, age and type. Create an employee value object and add it to the list. Step 4: At the end iterate through the list and print the employees to verify we parsed it right. Using SAX: Step 1: Create a Sax parser and parse the xml Step 2: In the event handler create the employee object Step 3 : Print out the data
69
PROGRAM: 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>
70
Using DOM DomParserExample.java a) Getting a document builder private void parseXmlFile(){ //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = 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 elements
71
Get the rootElement from the DOM object.From the root element get all employee elements. Iterate through each employee element to load the data. private void parseDocument(){ //get the root element Element docEle = dom.getDocumentElement(); //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("Employee"); if(nl != null && nl.getLength() > 0) { for(int i = 0 ; i < nl.getLength();i++) { //get the employee element Element el = (Element)nl.item(i); //get the Employee object Employee e = getEmployee(el); //add it to list myEmpls.add(e); } } } c) Reading in data from each employee.
72
/** * I take an employee element and read the values in, create * an Employee object and return it */ private Employee getEmployee(Element empEl) { //for each <employee> element get text or int values of //name ,id, age and name String name = getTextValue(empEl,"Name"); int id = getIntValue(empEl,"Id"); int age = getIntValue(empEl,"Age"); String type = empEl.getAttribute("type"); //Create a new Employee with the value read from the xml nodes Employee e = new Employee(name,id,age,type); return e; } /** * I take a xml element and the tag name, look for the tag and get * the text content * i.e for <employee><name>John</name></employee> xml snippet if * the Element points to employee node and tagName is 'name' I will return John
73
*/ private String getTextValue(Element ele, String tagName) { String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if(nl != null && nl.getLength() > 0) { Element el = (Element)nl.item(0); textVal = el.getFirstChild().getNodeValue(); } return textVal; } /** * Calls getTextValue and returns a int value */ private int getIntValue(Element ele, String tagName) { //in production application you would catch the exception 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();
74
while(it.hasNext()) { System.out.println(it.next().toString()); } } Using Sax SAXParserExample.java a) Create a Sax Parser and parse the xml private void parseDocument() { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try { //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs sp.parse("employees.xml", this); }catch(SAXException se) { se.printStackTrace(); }catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch (IOException ie) { ie.printStackTrace();
75
} } b) In the event handlers create the Employee object and call the corresponding setter methods. //Event Handlers public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { //reset tempVal = ""; if(qName.equalsIgnoreCase("Employee")) { //create a new instance of employee tempEmp = new Employee(); tempEmp.setType(attributes.getValue("type")); } } public void characters(char[] ch, int start, int length) throws SAXException { tempVal = new String(ch,start,length); } public void endElement(String uri, String localName String qName) throws SAXException { if(qName.equalsIgnoreCase("Employee")) {
76
//add it to the list 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() + "'."); terator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } }
77
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 done and executed successfully.
78
AIM: To create Sample web application development in the open source environment. ALGORITHM: Step1: start the program Step2: Inside the asp definition tag include the html contents Step3: include the code for the database connectivity using the ado object Step4: select all the data form the student table Step5: Traverse all the tuples in the table Step6: Print the data Step7: close the connection Step8: stop the program
79
PROGRAM: access.asp file: <% Option Explicit %> <html> <% DIM name set 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"> </form> </html>
80
OUTPUT:
RESULT: Thus the Sample web application development in the open source environment has been executed successfully executed.
81