Vous êtes sur la page 1sur 65

EX.

NO: 1 DATE: AIM:-

TO CREATE A WEBPAGE USING HTML TAGS

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

Ex. No: 02 DATE: Aim:

HTML WITH INTERNAL AND EXTERNAL CSS

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> { 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.

Ex. No: 3.a DATE: Aim:

DATE COMPARISION USING JAVA SCRIPT

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

10

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); } } function recalcDateDiff() { var myForm = document.form1; var firstDay =

11

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;

12

} </SCRIPT> </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> </P> <P> Select End Date<BR> <SELECT NAME="secondDay" SIZE="1" onchange= "return recalcDateDiff()"> <SCRIPT LANGUAGE=JavaScript> writeOptions(1,31); </SCRIPT> </SELECT>

13

<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> 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>

14

OUTPUT:

RESULT: Thus the given program was coded and executed successfully.

15

Ex. No: 3.b DATE: Aim:

FORM VALIDATION USING JAVA SCRIPT

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.

16

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

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">'+"Alternate Email: "+'</font>'+document.signup.aemail.value);

18

} --> </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 Signup Form </font></h2> <form name="signup" onSubmit="return validate()"> <font size="2"> <p>&nbsp;&nbsp;*First 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; <input type="password" name="pword1">(min 6 characters)</p> <p style=" border:">&nbsp;&nbsp;*Confirm Password: <input type="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"> Name:<input type="text" name="fname" face="Verdana, Arial, Helvetica, sans-serif" color="#660000"

19

<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:<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>

20

OUTPUT:

RESULT: Thus the given program was coded and executed successfully.

21

Ex.No:4 DATE: Aim:

ONLINE BOOK SHOPPING USING JSP OBJECTS

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.

22

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"> <inputtype="submit"value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value="clear"> </form> </body> </html> type="reset"

23

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">

24

<inputtype="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"> </form> </body> </html> 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 PASSWORD TITLE :<input type="text" name="id"><br> : <input type="password" name="pwd"><br> :<input type="text" name="title"><br> : <input type="text" name="no"><br>

NO. OF BOOKS DATE

: <input type="text" name="date"><br>

25

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.*% <% 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+ and password=+pwd+; ResultSet rs=stmt.executeQuery(sqlstmt); int flag=0; while(rs.next())

26

{ flag=1; } if(flag==0) { out.println(SORRY INVALID ID TRY AGAIN ID<br><br>); out.println( RETRY</a>); } else { out.println(VALID LOGIN ID<br><br>); out.println(<h3><ul>); <a href=\/tr1/login.html\>press LOGIN to

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);

27

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>);

28

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(); 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>);

29

} 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>);

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>);

30

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; } }

31

if(flag==0) { 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>); } 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 href=\/tr1/order.html\>press HERE to RETRY

32

33

OUTPUT:

34

35

Result: Thus the given program was coded and executed successfully.

36

Ex.No:5 DATE: AIM:

SERVLET PROGRAM USING HTTP SERVLET

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

37

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> Java Servlet Code : import java.io.*; 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");

38

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"); } } }

39

Output:

Result: Thus the given program was coded and executed successfully.

40

Ex.No:06 DATE: Aim:

ONLINE SHOPPING DATABASE APPLICATION

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.

41

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 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> { text-decoration: none; color: #FFFFFF; font-weight: bold } http-equiv="Content-Type" content="text/html; charset=windows-

42

<td width="67%" colspan="2" height="81">&nbsp;</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">&nbsp;</td> <td width="50%" bgcolor="#336699" align="center" height="19">&nbsp;</td> </tr> </table> <p>&nbsp;</p> <% 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 "POST","http://localhost/xmlDatabase/datasource.asp",

43

response.write XMLDom.transformNode(XSLDom) %> <% 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" rs.open query,conn,3,1 %> <recordset total="<%=rs.recordcount%>"> <head> <%for each fld in rs.fields%> <field name="<%=fld.name%>"/> <%next%> </head> <rows>

44

<%do until rs.eof%> <row> <%for each fld in rs.fields%> <col><%=fld.value%></col> <%next%> </row> <%rs.movenext%> <%loop%> </rows> </recordset> <% rs.close conn.close set conn = nothing set rs= nothing 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>

45

</xsl:template> <xsl:template match="col"> <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"> <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>

46

Output:

Result: Thus the given program was coded and executed successfully.

47

Ex.No:07 DATE: AIM:

CREATION OF XML DOCUMENT FOR A SPECIFIC DOMAIN

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.

48

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> </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()">

49

<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> </STUDENT> <STUDENT> <REGNO>0002</REGNO> <NAME>DIVIYA</NAME> <COURSE>M.E CSE</COURSE> <SEM>II</SEM> </STUDENT> </note>

50

OUTPUT:

Result: Thus the given program was coded and executed successfully.

51

Ex.No:08 DATE: AIM:

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

52

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> <flag gender="F"/> </contact> <salutation>Dear Sir: </salutation> <paragraph>It is our privillege .........</paragraph> <closing>Sincerely</closing> <signature>Ms.aaaaa</signature> </letter>

53

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)>

54

OUTPUT:

RESULT: Thus the given program was coded and executed successfully.

55

Ex.No:09 DATE: AIM:

PARSING AN XML DOCUMENT USING DOM AND SAX PARSERS

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

56

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>

Using DOM DomParserExample.java a) Getting a document builder private void parseXmlFile(){ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse("employees.xml");

57

}catch(ParserConfigurationException pce) { pce.printStackTrace(); }catch(SAXException se) { se.printStackTrace(); }catch(IOException ioe) { ioe.printStackTrace(); } } b) Get a list of employee elements 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(){ 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; }

58

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; } 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 xml private void parseDocument() { SAXParserFactory spf = SAXParserFactory.newInstance(); try { SAXParser sp = spf.newSAXParser();

59

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 setter methods. public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { tempVal = ""; if(qName.equalsIgnoreCase("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);

60

} 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() + "'."); terator it = myEmpls.iterator(); while(it.hasNext()) { System.out.println(it.next().toString()); } }

61

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.

62

Ex. No: 10 DATE:

SAMPLE WEB APPLICATION DEVELOPMENT IN THE OPEN SOURCE ENVIRONMENT

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

63

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>

64

OUTPUT:

RESULT: Thus the Sample web application development in the open source environment has been executed successfully executed.

65

Vous aimerez peut-être aussi