wplab 4th sem MCA VTU by heera

80
Web Programming Laboratory 07MCA47 1.Develop and demonstrate a XHTML document that illustrates the use of external style sheet, ordered list, table, borders, padding, color, and the <span> tag. //XHTML document for timetable <html> <head>MCA<title>EvenSemester</title></head> <body> <style> .sahana { font-size:25; border-bottom-style:dashed; } </style> <CENTER><font color="blue" class=sahana>Rao Bahadur Y.Mahabaleshwarappa Engineering College</font> <h4>Department of Master of Computer Application</h4> <h5>Time-Table for Even Semester 2008-2009</h5> <h6 align="left">Sem:IV</h6></CENTER></head> <table border=10> <tr> <th width="8%">Day</th> <th>8:00-9:00AM</th> <th>9:00-10:00AM</th> <th width="20%" rowspan=4>10:00-10:30AM<br>B</br><br>R</br><br>E</br>A</br><br>K< /br></th> <th>10:30-11:30AM</th> <th>11:30-12:30PM</th> <th width="20%" rowspan=6>12:30-2:00PM <br>L</br><br>U</br><br>N</br><br>C</br><br>H</br></th> <th>2:00-3:00PM</th> <th>3:00-4:00PM</th> <th>4:00-5:00PM</th> </tr> Dept of MCA, RYMEC, Bellary. 2008-2009 Page 1

description

4th sem MCA VTU web programming lab programming

Transcript of wplab 4th sem MCA VTU by heera

Page 1: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

1.Develop and demonstrate a XHTML document that illustrates the use of external style sheet, ordered list, table, borders, padding, color, and the <span> tag.

//XHTML document for timetable

<html><head>MCA<title>EvenSemester</title></head><body><style>.sahana{font-size:25;border-bottom-style:dashed; }</style><CENTER><font color="blue" class=sahana>Rao Bahadur Y.Mahabaleshwarappa Engineering College</font> <h4>Department of Master of Computer Application</h4><h5>Time-Table for Even Semester 2008-2009</h5><h6 align="left">Sem:IV</h6></CENTER></head><table border=10><tr><th width="8%">Day</th><th>8:00-9:00AM</th><th>9:00-10:00AM</th><th width="20%" rowspan=4>10:00-10:30AM<br>B</br><br>R</br><br>E</br>A</br><br>K</br></th><th>10:30-11:30AM</th><th>11:30-12:30PM</th><th width="20%" rowspan=6>12:30-2:00PM <br>L</br><br>U</br><br>N</br><br>C</br><br>H</br></th><th>2:00-3:00PM</th><th>3:00-4:00PM</th><th>4:00-5:00PM</th></tr><tr align="center"><td>Mon</td><td><a href="g.html#WP">WP</a></td><td><a href="g.html#EA-1">EA-1</a></td><td><a href="g.html#SE">SE</a></td><td><a href="g.html#ADA">ADA</a></td><td><a href="g.html#USP">USP</a></td><td colspan=2>ADA(B3)</td></tr><tr align="center"><td>Tue</td>

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 1

Page 2: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

<td><a href="g.html#SE">SE</a></td><td><a href="g.html#ADA">ADA</a></td><td><a href="g.html#EA-1">EA-1</a></td><td>-</td><td><a href="g.html#USP">USP</a></td><td colspan=2>WP(B3)</td></tr><tr align="center"><td>Wed</td><td><a href="g.html#ADA">ADA</a></td><td><a href="g.html#USP">USP</a></td><td><a href="g.html#EA-1">EA-1</a></td><td>-</td><td><a href="g.html#SE">SE</a></td><td><a href="g.html#WP">WP</a></td><td>-</td></tr><tr align="center"><td>Thur</td><td colspan=4>ADA(B3)(Upto 11:00)</td><td><a href="g.html#WP">WP</a></td><td><a href="g.html#EA-1">EA-1</a></td><td colspan=2>JAVA(B3)</td></tr><tr align="center"><td>Fri</td><td><a href="g.html#USP">USP</a></td><td><a href="g.html#SE">SE</a></td><td>BREAK</td><td><a href="g.html#WP">WP</a></td><td><a href="g.html#ADA">ADA</a></td><td colspan=3>JAVA(B3)</td></tr><tr align="center"><td>Sat</td><td colspan=5>WP(B3)(Upto 11:00)</td></tr></table><table border=2 width="100%"><tr><td>EA-1 Shivanand.K.B</td><td>SE A.T.Satyanarayana Reddy</td></tr><tr><td>WP T.Heera Singh</td><td>ADA E.N.V Rajesh</td></tr><tr><td>USP T.Hanumantha Reddy</td>

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 2

Page 3: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

<td>JavaLaboratory Shivanand.K.B</td></tr><tr><td>WebProgrammingLaboratory T.Heera Singh</td><td>ADALaboratory E.N.V.Rajesh</td></tr></table></body></html>

//XHTML document for linking Syllabus for particular subject(g.html)

<html><head><title>Syllabus Page</title></head><body><a href="timetable.html">back to timetable</a><p id="EA-1"><h1>EA-1</h1><ol type="1"><li>Introduction to Java<li>Classes,Inheritance,Exceptions,Applets<li>Multi Threaded Programming,Event Handling<li>Swings<li>Java 2 Enterprise Edition Overview,Database Access<li>Servlets<li>JSP,RMI<li>Enterprise Java Beans</ol><a href="timetable.html">back to timetable</a><p id="SE"><h1>SE</h1><ol type="1"><li>Overview<li>Critical Systems,Software Processes<li>REquirements<li>System models,Project Management<li>Software Design<li>Development<li>Verification and Validation<li>Management</ol><a href="timetable.html">back to timetable</a><p id="WP"><h1>WP</h1><ol type="1"><li>Fundamentals of web,XHTML-1<li>XHTML-2,CSS<li>JavaScript

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 3

Page 4: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

<li>JavaScript and HTML Documents,Dynamic Documents with JavaScript<li>XML<li>Perl,CGI Programming<li>PHP<li>Database Access</ol><a href="timetable.html">back to timetable</a><p id="ADA"><h1>ADA</h1><ol type="1"><li>Introduction<li>Fundamentals of the Analysis of Algorithm Efficiency<li>Divide and Conquer<li>Decrease and Conquer<li>Transform and Conquer<li>Space and Time Tradeoffs<li>Dynamic Programming<li>Greedy Techniques<li>Limitations of Algorithm Power<li>Copying with the Limitations of Algorithm Power</ol><a href="timetable.html">back to timetable</a><p id="USP"><h1>USP</h1><ol type="1"><li>Introduction<li>UNIX Files<li>UNIX File APIs<li>UNIX Processes<li>Process Control<li>Signals and Daemon Processes<li>Interprocess Communication-1<li>Interprocess Communication-2</ol></body></html>

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 4

Page 5: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Output for timetable.html XHTML document:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 5

Page 6: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Output for g.html XHTML document: It links to particular subject when clicked on that particular subject in timetable.

WP1. Fundamentals of web,XHTML-1 2. XHTML-2,CSS

3. JavaScript

4. JavaScript and HTML Documents,Dynamic Documents with JavaScript

5. XML

6. Perl,CGI Programming

7. PHP

8. Database Access

back to timetable

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 6

Page 7: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

2. Develop and demonstrate a XHTML file that includes Javascript for the following problemsa) Input: A number n obtained using prompt Output: The first n Fibonacci numbers

<html><head><title>Fibonacci series</title></head><body><script language="Javascript">var f1=0,f2=1,f3,i;var n=prompt("Enter the limit"," ");document.writeln("fibonacci series","</br>",f1,"</br>",f2,"</br>");for(i=2;i<n;i++){f3=f1+f2;document.write(f3+"</br>");f1=f2;f2=f3;}</script></body></html>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 7

Page 8: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 8

Page 9: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

2.b) Input: A number n obtained using prompt

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 9

Page 10: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Output: A table of numbers from 1 to n and their squares using alert<html><head><marquee style="font family:sahana";>Multiplication Table</marquee></head><body><table><script language="javascript">var m1,m2,i,n,j,sqr;var str="squares";n=prompt("enter the number"," ");for(j=1;j<=n;j++){sqr=j*j;str+=("\n"+j+"*"+j+"="+sqr);}alert(str);for(i=1;i<=10;i++){for(j=1;j<=n;j++){document.write("<td>");m1=i*j;document.write(j,"*",i,"=",m1);}document.write("<tr>");}</script></body></html>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 10

Page 11: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 11

Page 12: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

3. Develop & demonstrate a XHTML file that includes javascript that uses functions for the following problems:a) Parameter: A String Output: The position in the string of the left-most vowel

<html><head><title>Left-most vowel</title><script language="javascript">function vowel(){var str=document.myform.result.value;var c,i;for(i=0;i<str.length;i++){c=str.charAt(i);if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U'){return(i+1);}}return -1;}function display(){var i=vowel();if(i==-1)document.myform.mytext.value="vowel not found";elsedocument.myform.mytext.value="vowel found at"+i;}</script></head><body><form name="myform"><input type="text" name="result" value=" "><input type="text" name="mytext"value=" "readonly><input type="button" name="btn" value="find leftmost vowel" onclick="display()"></form></body></html>Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 12

Page 13: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

3.b) Parameter: A number

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 13

Page 14: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Output: The number with its digits in the reverse order

<html><head><title>Reverse of a given number</title></head><body><script language="javascript">function reverse(num){var rev=0,n1=num,rem;while(num>0){rem=parseInt(num%10);rev=parseInt(rev*10+rem);num=parseInt(num/10);}document.write("Numbers are=",n1,"</br>");document.write("Reverse numbers=",rev);}var num=prompt("Enter number to find reverse number","");reverse(num);</script></body></html>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 14

Page 15: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

4.a) Develop and demonstrate, using Javascript , a XHTML document that collects

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 15

Page 16: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

the USN ( the valid format is: A digit from 1 to 4 followed by two upper-case charactersfollowed by two digits followed by two upper-case characters followed by three digits;no embedded spaces allowed) of the user. Event handler must be included for the formelement that collects this information to validate the input. Messages in the alertwindows must be produced when errors are detected.

//html file for usn<html><head><title>Illustrate form input validation</title><script type="text/javascript" src="usn.js"></script></head><body><h3>Collects the USN</h3><form action = ""><p> USN <input type="text" id="USNName"> </br></br></br> <input type="reset" id="reset"> <input type="button" value="check" onclick="chkName()"/> </p></form></body></html>

//usn.jsfunction chkName(){var myName=document.getElementById("USNName");var str="20";var d=new Date();var temp=new RegExp("^[1-4]{1}[A-Z]{2}[\\d]{2}[A-Z]{2}[\\d]{3}$");var t=temp.test(myName.value);if(t==false){alert("USN entered is wrong");}Else{

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 16

Page 17: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

alert("USN entered is Correct");}

}

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 17

Page 18: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 18

Page 19: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

4.b). Modify the above program to get the current semester also.

//html file for USN<html><head><title>Illustrate form input validation</title><script type="text/javascript" src="usn1.js"></script></head><body><h3>Collects the USN</h3><form action = ""><p> USN <input type="text" id="USNName"> </br></br></br> <input type="reset" id="reset"> <input type="button" value="check" onclick="chkName()"/> </p></form></body></html>

//javascript for usn1.jsfunction chkName(){var myName=document.getElementById("USNName");var str="20";var d=new Date();var temp=new RegExp("^[1-4]{1}[A-Z]{2}[\\d]{2}[A-Z]{2}[\\d]{2,3}$");var t=temp.test(myName.value);if(t==false)

{alert("USN entered is wrong");}else{

str+=myName.value.charAt(3);str+=myName.value.charAt(4);str=parseInt(str);var cur=d.getYear();

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 19

Page 20: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

var mon=d.getMonth();str=cur-str;str*=2;if(mon<6)str=str;elsestr+=1;if(str<=8)alert("current semester:"+str);elsealert("Semester Beyonds 8 sem");myName.focus();myName.select();}}

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 20

Page 21: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 21

Page 22: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

5. a) Develop and demonstrate, using Javascript script, a XHTML document that contains three short paragraphs of text, stacked on top of each other, with only enough of each showing so that the mouse cursor can be placed over some part of them. When the cursor is placed over the exposed part of any paragraph, it should rise to the top to become completely visible.

<html><head><title>New Document</title><script language="javascript">function fun1(){document.getElementById("first").style.visibility="visible";var second=document.getElementById("second");second.style.top=100;var third=document.getElementById("third");}function fun2(){document.getElementById("first").style.visibility="visible";var second=document.getElementById("second");var third=document.getElementById("third");}function fun3(){document.getElementById("seconda").style.visibility="visible";var second=document.getElementById("third");third.style.top=160;}function fun4(){document.getElementById("seconda").style.visibility="visible";var third=document.getElementById("third");}function fun5(){document.getElementById("thirda").style.visibility="visible";}function fun6(){document.getElementById("thirda").style.visibility="visible";}</script></head><body><span style="position:absolute;top:40;left:25" onmouseover="fun1()" onmouseout="fun2()">

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 22

Page 23: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

place mouse here to view first paragraph</span><br><span id="first" style="position:absolute;top:60;left:25;visibility:hidden;">If file sharing is prohibited in your country,dont download it</span><span id="second" style="position:absolute;top:80;left:25;" onmouseover="fun3()" onmouseout="fun4()">place mouse here to view second paragraph</span><br><span id="seconda" style="position:absolute;top:120;left:25; visibility:hidden">This activity is just for Test/Backup purpose only</span><span id="third" style="position:absolute;top:120;left:25;" onmouseover="fun5()" onmouseout="fun6()">Place mouse here to view third paragraph</span><br><span id="thirda" style="position:absolute;top:180;left:25; visibility:hidden">This activity is just for test/backup pupose only</span></body></html>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 23

Page 24: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

5.b)Modify the above document so that when a paragraph is moved from the top

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 24

Page 25: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Stacking position, it returns to its original position rather than to the bottom.

<html><head><title>New Document</title><script language="javascript">function fun1(){document.getElementById("first").style.visibility="visible";var second=document.getElementById("second");second.style.top=150;var third=document.getElementById("third");third.style.top=180;}function fun2(){document.getElementById("first").style.visibility="hidden";var second=document.getElementById("second");second.style.top=70;var third=document.getElementById("third");third.style.top=90;}function fun3(){document.getElementById("seconda").style.visibility="visible";var second=document.getElementById("third");third.style.top=180;}function fun4(){document.getElementById("seconda").style.visibility="hidden";var third=document.getElementById("third");third.style.top=90;}function fun5(){document.getElementById("thirda").style.visibility="visible";}function fun6(){document.getElementById("thirda").style.visibility="hidden";

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 25

Page 26: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

}</script></head><body><span style="position:absolute;top:40;left:25" onmouseover="fun1()" onmouseout="fun2()"> place mouse here to view first paragraph</span><br><span id="first" style="position:absolute;top:60;left:25;visibility:hidden;">If file sharing is prohibited in your country,dont download it</span><span id="second" style="position:absolute;top:80;left:25;" onmouseover="fun3()" onmouseout="fun4()">place mouse here to view second paragraph</span><br><span id="seconda" style="position:absolute;top:100;left:25; visibility:hidden">This activity is just for Test/Backup purpose only</span><span id="third" style="position:absolute;top:140;left:25;" onmouseover="fun5()" onmouseout="fun6()">Place mouse here to view third paragraph</span><br><span id="thirda" style="position:absolute;top:160;left:25; visibility:hidden">This activity is just for test/backup pupose only</span></body></html>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 26

Page 27: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 27

Page 28: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

6. a) Design an XML document to store information about a student in an engineeringcollege affiliated to VTU. The information must include USN, Name, Name of theCollege, Branch, Year of Joining, and e-mail id. Make up sample data for 3 students.Create a CSS style sheet and use it to display the document.

//xml document<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited by XMLSpy® --><?xml-stylesheet type="text/css" href="6a.css"?><STUDENT>

<DETAILS><TITLE>STUDENT INFORMATION</TITLE></DETAILS><DETAILS>

<USN><a>USN:</a>3VC07MCA36</USN><NAME><a>NAME:</a>SAHANA</NAME><COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE><BRANCH><a>BRANCH:</a>MCA</BRANCH><YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING><EMAIL-ID><a>Email-id:</a>[email protected]</EMAIL-ID>

</DETAILS><DETAILS>

<USN><a>USN:</a>3VC07MCA40</USN><NAME><a>NAME:</a>SWETHA</NAME><COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE><BRANCH><a>BRANCH:</a>MCA</BRANCH><YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING><EMAIL-ID><a>Email-id:</a>[email protected]</EMAIL-ID>

</DETAILS><DETAILS>

<USN><a>USN:</a>3VC07MCA43</USN><NAME><a>NAME:</a>VARNIKA</NAME><COLLEGE><a>COLLEGE:</a>R.Y.M.E.C</COLLEGE><BRANCH><a>BRANCH:</a>MCA</BRANCH><YEAROFJOINING><a>Year of Joining:</a>2007</YEAROFJOINING><EMAIL-ID><a>Email-id:</a>[email protected]</EMAIL-ID>

</DETAILS></STUDENT>

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 28

Page 29: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

//6a.css document

STUDENT{}DETAILS{display:block; color:"black";font-size:20pt; font-family:"Times New Roman";font-weight:bold;border-style:solid;}TITLE{color:"yellow";font-size:20pt; font-family:"Times New Roman";text-decoration:underline;text-indent:1.5in;}a{text-align:"left";color:"black"; font-size:18pt; font-family:"Times New Roman";}USN{display:block; color:"black"; font-size:18pt; font-family:"Times New Roman";}NAME{display:block;color:"black"; font-size:18pt;

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 29

Page 30: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

font-family:"Times New Roman";}COLLEGE{display:block;color:"black";font-size:18pt; font-family:"Times New Roman";}BRANCH{display:block;color:"black";font-size:18pt; font-family:"Times New Roman";}YEAROFJOINING{display:block;color:"black";font-size:18pt; font-family:"Times New Roman";}EMAIL-ID{display:block; color:"black";font-size:18pt; font-family:"Times New Roman";}

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 30

Page 31: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

b) Create an XSLT style sheet for one student element of the above document and use it

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 31

Page 32: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

to create a display of that element.

//xml document<?xml-stylesheet type="text/xsl" href="6b.xsl"?><STUDENT><details><USN>3VC07MCA43</USN><NAME>Varnika</NAME><COLLEGE>R.Y.M.E.C</COLLEGE><BRANCH>MCA</BRANCH><YEAR>2007</YEAR><EMAIL-ID>[email protected]</EMAIL-ID></details></STUDENT>

//xsl document<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XHTML"><xsl:template match="STUDENT"><html><head><title>xsl document</title></head><body><h2><center>STUDENT INFORMATION</center></FONT></h2><table border="3" allign="center"><tr><th><span style="font-style:italic;font-size:25;">USN:</span></th><th><span style="font-style:italic;font-size:25;">NAME:</span></th><th><span style="font-style:italic;font-size:25;">COLLEGE:</span></th><th><span style="font-style:italic;font-size:25;">BRANCH:</span></th><th><span style="font-style:italic;font-size:25;">YEAR OF JOINING:</span></th><th><span style="font-style:italic;font-size:25;">EMAIL-ID:</span>

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 32

Page 33: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

</th></tr><xsl:for-each select="details"><tr><td><xsl:value-of select="USN"/></td><td><xsl:value-of select="NAME"/></td><td><xsl:value-of select="COLLEGE"/></td><td><xsl:value-of select="BRANCH"/></td><td><xsl:value-of select="YEAR"/></td><td><xsl:value-of select="EMAIL-ID"/></td></tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>

Output:

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 33

Page 34: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

7. a) Write a Perl program to display various Server Information like Server Name, Server

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 34

Page 35: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Software, Server protocol, CGI Revision etc.

#!/perl/bin/perl.exeuse CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 1a');print $cgi->h1('Server Informations');print $cgi->hr;print "<table border=4 cellpadding=2>";print "<tr><td>SERVER_NAME: </td><td>", $ENV{'SERVER_NAME'}, "</td></tr>";print "<tr><td>SERVER_PROTOCOL: </td><td>", $ENV{'SERVER_PROTOCOL'}, "</td></tr>";print "<tr><td>SERVER_SOFTWARE: </td><td>", $ENV{'SERVER_SOFTWARE'}, "</td></tr>";print "<tr><td>GATEWAY_INTERFACE:</td><td>", $ENV{'GATEWAY_INTERFACE'}, "</td></tr>";print "</table>";print $cgi->end_html;

OUTPUT:Start>Run>http://localhost/cgi-bin/prog1a.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 35

Page 36: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

7.b. Write a Perl program to accept UNIX command from a HTML form and to display the output of the command executed.

#!/perl/bin/perl.exeuse CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 1b');print $cgi->h1('Unix Command Executor');print $cgi->hr;print $cgi->h3('Please enter the unix command');print $cgi->start_form( -method=>'post', -action=>'/cgi-bin/prog1b.cgi');print "Unix Command:";print $cgi->textfield( -name=>'command',-value=>'');print $cgi->submit( -name=>'submit',-value=>'Execute');print $cgi->endform;print $cgi->hr;$command=$cgi->param("command");if($command ne ""){print " The output of the unix command: $command";$output=`$command`;print "<pre>";print $output;print "</pre>";}print $cgi->hr;print $cgi->end_html;

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 36

Page 37: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

OUTPUT:Start>Run>http://localhost/cgi-bin/prog1a.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 37

Page 38: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

8. a) Write a Perl program to accept the User Name and display a greeting message randomly chosen from a list of 4 greeting messages.

#!/perl/bin/perl.exe use CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 2a');print $cgi->h1('Greeting a User');print $cgi->hr;print $cgi->h3('Dear User <br> Enter the username');print $cgi->start_form( -method=>'post',-action=>'/cgi-bin/greet.cgi');print "User Name:";print $cgi->textfield( -name=>'username',-value=>'');print $cgi->submit( -name=>'submit',-value=>'Process');print $cgi->reset ;print $cgi->endform;print $cgi->hr;print $cgi->end_html;

Save: C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\prg8.cgi

#!/perl/bin/perl.exe use CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 3');print $cgi->h1('<center>Welcome</center>');print "$username";print $cgi->hr;($sec,$min,$hour)=localtime(time);if($hour> 23 || $hour< 6){$greet="u r 2 early";}elsif($hour>= 6 && $hour< 12){$greet="a very gud mrg 2 u";}elsif($hour>= 12 && $hour< 18){$greet="gud afternoon 2 u";}else{

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 38

Page 39: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

$greet="gud nite";} $time=sprintf("%02d:%02d:%02d",$hour,$min,$sec); print"<font size=5+ color=blue><center>the time is</font><font size=10+ color=red> $time <h2><i>$greet</i></h2>";

Save: C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\greet.cgi

OUTPUT:Start>Run>http://localhost/cgi-bin/prg8.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 39

Page 40: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

8.b) Write a Perl program to keep track of the number of visitors visiting the web page and to display this count of visitors, with proper headings.

#!/perl/bin/perl.exeuse CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 8b');print $cgi->h1('<center>Server Page Visited Informations</center>');print $cgi->hr;$count_file="c:/count.txt";if(open(FILE,"<".$count_file)) {

$no_accesses=<FILE>;close(FILE);if(open (FILE,">".$count_file)) {

$no_accesses++;print FILE $no_accesses;close(FILE);

}else {

print "Cannot write the file. No Visitors information in the server";} } else {

print "cannot read the counter database for visitors";}print "Welcome User";print "<BR><BR>This page has been accessed <font color=red size=10> $no_accesses </font> times from the creation";print $cgi->end_html;

Save: C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\8b.cgi

Create one file named count.txtSave: C:\count.txt

OUTPUT:Start>Run>http://localhost/cgi-bin/8b.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 40

Page 41: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 41

Page 42: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

9. Write a Perl program to display a digital clock which displays the current time of the server.

#!c:/perl/bin/perl.exeuse CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 9');print $cgi->h1('<center>Server Time on Digital Clock');print $cgi->hr;($seconds,$minutes,$hour)=localtime(time);if($hour>12) {$hour-=12;$ampm='PM';}else{$ampm='AM';}if($hour==0){$hour=12;}$time=sprintf("%02d:%02d:%02d %s",$hour,$minutes,$seconds,$ampm);print "User: the Time is<br><br>";print $time."</center>";print $cgi->hr;print $cgi->end_html;

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 42

Page 43: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

OUTPUT:Start>Run>http://localhost/cgi-bin/prog9.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 43

Page 44: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

10. Write a Perl program to insert name and age information entered by the user into a table created using MySQL and to display the current contents of this table.#!c:/perl/bin/perl.exe## 6. Program to insert new name and age into the database.#use Win32::ODBC;use CGI;$cgi=new CGI;print $cgi->header;print $cgi->start_html('Program 6');print $cgi->h1('<center>Database Insertion Operation</center>');print $cgi->hr;$database=new Win32::ODBC("myown");$table="myown";print "<center>Enter the information below to save.<br><br>";$query="select max(userid) from $table";$database->Sql($query);@fieldnames=$database->FieldNames();print "<form method=post action=/cgi-bin/prog6save.cgi>";print $cgi->table({-border=>0,-cellpadding=>10,-cellspacing=>0});print $cgi->caption('<b><i>User Information</i></b>');if($database->FetchRow()){

%data=$database->DataHash();print $cgi->Tr({-valign=>top,-align=>center});print $cgi->td('Userid');print "<input type=hidden name=userid value=".++$data{'max(userid)'}.">";print $cgi->td('<input type=text name=userid value='.$data{'max(userid)'}.'

disabled>');}

print $cgi->Tr({-valign=>top,-align=>center});print $cgi->td('Name:');print $cgi->td('<input type=text name=name1>');print $cgi->Tr({-valign=>top,-align=>center});print $cgi->td('Age:');print $cgi->td('<input type=text name=age>');print $cgi->Tr({-valign=>top,-align=>center});print $cgi->td;

print $cgi->td('<input type=submit value=Submit> <input type=reset value=Clear>');

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 44

Page 45: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

print "</table>";print "</form></center>";print $cgi->end_html;

Save: C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\prog6.cgi

#!c:/perl/bin/perl.exe# prog6save.cgi - 2nd part#Program to get and insert new name and age information into the database.#use CGI;use Win32::ODBC;$cgi=new CGI;print $cgi->header;print $cgi->start_html('2nd part of program 6');print $cgi->h1('<center>Database Save Information');print $cgi->hr;$userid=$cgi->param('userid');$name=$cgi->param('name1');$age=$cgi->param('age');$database=new Win32::ODBC("myown");$query="insert into myown values(\'$name\',$age)";$database->Sql($query);print "Dear user $name:<br><br>";print "Your information has been saved";print "<br><br><a href=/cgi-bin/prog6.cgi>Back</a></center>";print $cgi->hr;print $cgi->end_html;

Save: C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\prog6save.cgi

Start>all programs>MySQL>MySQL Server 5.1>MySQL Command Line Client>Enter password***mysql> create user 'varnika' identified by 'varnika';Query OK, 0 rows affected (0.05 sec)

mysql> create database library;Query OK, 1 row affected (0.03 sec)

mysql> use library

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 45

Page 46: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Database changed

mysql> create table myown -> ( -> name char(10), -> age int);Query OK, 0 rows affected (0.13 sec)

OUTPUT:1.Start>control panel>administrative toos> Data Sources (ODBC)>2.select system DSN tab>add>click3.Select MySQL server 5.1 Driver4. Data Source Name:myown5.Server:localhost6.User:varnika7.password:varnika8.data base:library9:click ok,ok,ok.

Start>run> http://localhost/cgi-bin/prog6.cgi

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 46

Page 47: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

See output in Mysql.

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 47

Page 48: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

11. Write a PHP program to store current date-time in a COOKIE and display the ‘Last visited on’ date-time on the web page upon reopening of the same page. <?// get current date information as associative arrayif(isset($_COOKIE['Datee'])){$cookiedate = $_COOKIE['Datee'];}$todayh = getdate();$d = $todayh[mday];$m = $todayh[mon];$y = $todayh[year];$hr = $todayh[hours];$mi = $todayh[minutes];$se = $todayh[seconds];$datestring ="$d-$m-$y, $hr:$mi:$se";setcookie("Datee",$datestring);print "Program for creating and displaying cookie";print"<br>";echo "<br>Hello, ".$cookiedate."! last visited!";print"<br>";?>

Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\prg11.php

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 48

Page 49: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

RunStart>run> http://localhost/prg11.php

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 49

Page 50: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

12. Write a PHP program to store page views count in SESSION, to increment the count on each refresh, and to show the count on web page.

<?phpsession_start();if(isset($_SESSION['count'])){print "Your session count: ".$_SESSION['count']. "<br>"; $_SESSION['count']++;} else { $_SESSION['count'] = 1;print "Session does not exist";}?>

Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php12.php

Output:-

RunStart>run> http://localhost/prg12.php

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 50

Page 51: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

After refresh the sessions output is viewed as below.

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 51

Page 52: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

13. Create a XHTML form with Name, Address Line 1, Address Line 2, and E-mail text fields. On submitting, store the values in MySQL table. Retrieve and display the data based on Name.

<HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY bgcolor=cyan><form method="get" action="php13.php"><br><FONT COLOR="orange"><h1><center>BOOK INFORMATION</h1><table align=center><tr><td>Enter Name</td><td><input type="text" name="name"></td></tr><tr><td>enter address1</td><input type="text" name="add1"></td></tr><tr><td>enter address2</td><input type="text" name="add2"></td></tr><tr><td>enter email</td><input type="text" name="email"></td></tr></table><br><br><center><input type="reset" value="CLEAR"><br><br><center><input type="submit" value="INSERT"></form></BODY></HTML>Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php13.html

<html><head><title> name and address database with MySQL </title></head><body><?php// Connect to MySQL

$db = mysql_connect("localhost", "anu", "anu");if (!$db) { print "Error - Could not connect to MySQL"; exit;}$name = $_GET['name'];$add1 = $_GET['add1'];

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 52

Page 53: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

$add2 = $_GET['add2'];$email = $_GET['email'];$sname=$_GET[‘sname’];$c = "insert into contact (name,add1,add2,email) values ('" . $name . "','" . $add1 . "','" . $add2 . "','" . $email . "')"; $er = mysql_select_db("emp");if (!$er) { print "Error - Could not select the EMP database" . mysql_error(); exit;}$a = mysql_query( $c );$res = mysql_query("select * from contact where name = '$sname'");$count = mysql_num_rows($res);$col = mysql_num_fields($res);//print "Totoal Cols present in Book Table " . $col . "<br>";print "<table border=1>";

while ( $row = mysql_fetch_array($res)){print "<tr>";

$i=0;while($i < $col)

{print "<td>" . $row[$i];$i = $i +1;}

}?>

</body></html>

Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php13.php

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 53

Page 54: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Output:-Create a table in Mysql with name person and with attributes in the program.Insert rows as shown below.

RunStart>run> http://localhost/php13.html

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 54

Page 55: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 55

Page 56: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

14. Using PHP and MySQL, develop a program to accept book information viz. Accession number, title, authors, edition and publisher from a web page and store the information

in a database and to search for a book with the title specified by the user and to display

the search results with proper headings.

<html><head><title> Access the library database with MySQL </title></head><body><?php// Connect to MySQL$db = mysql_connect("localhost", "varnika", "varnika");if (!$db) { print "Error - Could not connect to MySQL"; exit;}$acn = $_GET['acn'];$tit = $_GET['tit'];$aut = $_GET['aut'];$edi = $_GET['edi'];$pub = $_GET['pub'];$c = "insert into book (acn,tit,aut,edi,pub) values (" . $acn . ",'" . $tit . "','" . $aut . "','" . $edi . "','" . $pub . "')"; // Select the library database$er = mysql_select_db("library");if (!$er) { print "Error - Could not select the library database" . mysql_error(); exit;}$a = mysql_query( $c );$res = mysql_query("select * from book");$count = mysql_num_rows($res);$col = mysql_num_fields($res);print"<form action=pgm14.html><input type=submit value=BACK>";print"<h1>Book Information</h1>";print "<table border=1>";while ( $row = mysql_fetch_array($res)){

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 56

Page 57: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

print "<tr>";$i=0;while($i < $col)

{print "<td>" . $row[$i];$i = $i +1;}

}?></body></html>Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pgm14.php

<HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY><form method="get" action="pgm14.php"><br><h1><center>BOOK INFORMATION</h1><table align=center><tr><th>Enter acession number</th><td><input type="text" name="acn"></td></tr><tr><th>enter title</th><td><input type="text" name="tit"></td></tr><tr><th>enter author name</th><td><input type="text" name="aut"></td></tr><tr><th>enter edition </th><td><input type="text" name="edi"></td></tr><tr><th>enter publication</th><td><input type="text" name="pub"></td></tr></table><br><br><center><input type="reset" value="CLEAR"><br><br><center><input type="submit" value="INSERT"></form></BODY></HTML>

Save: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pgm14.html

Start>all programs>MySQL>MySQL Server 5.1>MySQL Command Line Client>Enter password***mysql> create user 'varnika' identified by 'varnika';Query OK, 0 rows affected (0.05 sec)

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 57

Page 58: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

mysql> create database library;Query OK, 1 row affected (0.03 sec)mysql> use libraryDatabase changedmysql> grant all on library.* to 'varnika'@'localhost' identified by 'varnika';Query OK, 0 rows affected (0.00 sec)mysql> create table book -> ( -> acn int, -> tit char(10), -> aut char(10), -> edi char(10), -> pub char(10) -> );Query OK, 0 rows affected (0.08 sec)OUTPUT:Start>Run>http://localhost/pgm14.html

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 58

Page 59: wplab 4th sem MCA VTU by heera

Web Programming Laboratory 07MCA47

Dept of MCA, RYMEC, Bellary. 2008-2009 Page 59