Final Web Lab Manual-1
Final Web Lab Manual-1
Develop and demonstrate a XHTML document that illustrates the use external style
sheet, ordered list, table, borders, padding, color, and the <span> tag.
xhtml.css
p.major {
font-size: 14pt;
font-style: italic;
font-family: 'Times New Roman';
}
p.minor {
font: 10pt bold 'Courier New';
}
h2 {
font-familY: 'Times New Roman';
font-size: 20pt; font-weight: bold
}
h3 {
font-family: 'Courier New';
font-size: 16pt;
color:red;
}
table {
border-top-width: medium;
border-bottom-width: thick;
border-top-color: red;
border-bottom-color: blue;
border-top-style: dotted;
border-bottom-style: dashed;
}
p {
border-style: dashed; border-width: thin; border-color: green
}
p.one {
padding: 0.2in;
background-color: #C0C0C0;
border-style: solid;
}
th.red {color: red}
th.orange {color: orange}
th.blue {color: blue}.spanred {font-size: 24pt; font-family: Ariel; color:
red;}
xhtml.html
<?xml version = "1.0" encoding = "utf-8"?>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>basic html tags</title>
<link rel = "stylesheet" type = "text/css" href="xhtml.css" />
</head>
<body>
<h3>Program that illustrates the use of the external style sheet</h3>
<p class = "major">
Welcome you all for the workshop on "Web Programming".
</p>
<p class = "minor">
Hope you enjoy the sessions and make it a grand success.
</p>
<h2> Introduction </h2>
<h3> 1.1 The Basics of WEB </h3>
<ol>
<li> Introduction to XHTML </li>
<li> Introduction XML </li>
<li> Introduction to javascript </li>
<li> Introduction to CSS </li>
<li> Introduction to Dynamic Documents </li>
</ol>
<table border = "5px">
<caption> Sessions dates </caption>
<tr>
<th></th>
<th class = "red"> xhtml </th>
<th class = "orange"> CSS</th>
<th class = "blue"> XML </th>
</tr>
<tr>
<th> Thur </th>
<td> 8-9 </td>
<td> 10-11 </td>
<td> 12-1 </td>
</tr>
<tr>
<th> Fri</th>
<td> 8-9 </td>
<td> 10-11 </td>
<td> 12-1 </td>
</tr>
<tr>
<th> Sat </th>
<td> 8-9 </td>
<td> 10-11 </td>
<td> 12-1 </td>
</tr>
</table>
<p>Now it is the time for all good Web programmers to learn to use style
sheets. </p>
<p class ="one">Now is the time for all good web programmers to learn to use
style sheets. <br ></p>
<p>Lab sessions are held in the <span class = "spanred"> afternoon.
</span></p></body></html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> fib.html </title>
</head>
<body style="background-color:yellow">
<h3 style="text-align:center;color:red"> Program to generate the
Fibonacci Series</h3>
<script type="text/javascript" >
var limit= prompt("Enter the limit 'n' to generate the fibonacci
series:","");
var f1=0;
var f2=1;
document.write("The limit entered to generate the fibonacci series
is:" , limit , "<br/>");
document.write("The fibonacci series: <br/>");
document.write("",f1,"<br/>");
document.write("",f2,"<br/>");
var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("",f3,"<br/>");
f1=f2;
f2=f3;
}
</script>
</body>
</html>
Screen 1: Run the program in the Netbeans. This opens a browser window along with the user prompt to
enter the limit to generate the Fibonacci series.
Screen 3: The program generates the Fibonacci series for limit entered.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> square.html </title>
</head>
<body style="background-color:yellow">
<h3 style="text-align:center;color:red"> Program to generate a table
of numbers from 1 to n and their squares using alert</h3>
<script type="text/javascript" >
var n= prompt("Enter the limit 'n' to generate the table of
numbers from 1 to n:","");
var msg = "";
var res = "0";
for(var x = 1; x <= n; x++)
{
res = x * x;
msg = msg + " "+ x + " * "+ x + " = " + res + "\n";
}
alert(msg);
</script>
</body>
</html>
Screen 1: Run the program in the Netbeans. This opens a browser window along with the user prompt to
enter the limit to generate square table.
Screen 3: The program generates the square table for limit entered using alert.
a) Parameter: A string
Output: The position in the string of the left-most vowel
b) Parameter: A number
Output: The number with its digits in the reverse order
}
document.write(" The entered string is:" +str+ "<br/>");
document.write(" The entered string has no vowels ");
}
</script>
</head>
<body style="background-color:yellow" onload="str_vowel();" >
<h3 style="text-align:center;color:red"> Program includes Javascript
script functions to find the position of the left-most vowel in the
entered string.</h3>
</body>
</html>
Screen 1: Run the program in the Netbeans. This opens a browser window along with the user prompt to
enter the string.
Screen 2: (Run 1): The string entered is BIET. The position of the left most vowel is 2
Screen 3: (Run 2): The string entered is rvwxyz. The entered string has no vowels.
Screen 1: Run the program in the Netbeans. This opens a browser window along with the user prompt to
enter the number.
b) Modify the above program to get the current semester also (restricted to be a number
from 1 to 8)
Screen 2: Run 1: Entered USN is (4bd06cs044), which is not in the correct format. The correct
format is 4BD06CS099, which is displayed on the alert box.
Screen 3: Run 2: Entered USN is 4BD06CS099, which is in the correct format. The alert box
displays the message saying it is in the correct format.
else
{
alert("Entered usn("+str.value+") is not in the correct form.\n"+
"The correct pattern is : 1RG07CS080\n"+
"Entered sem("+stsem.value+") is not in the correct range.\n"+
"The number is between 1 to 8\n"+
"Please go back and retype your USN & sem");
}
}
</script>
</head>
<body>
<h3>Student Information </h3>
<form name="my form">
<p> Enter your USN:</p>
<input type="text" id="usn" size=15/>
<br/>
<p> Enter your SEM:</p>
<input type="text" id="sem" size=15/>
<br/>
<br/>
<input type="button" onclick="checkusn()" value="validate"/>
<input type = "reset” value= "reset" />
<br/>
</form>
</body></html>
Screen 1: Run 1: Entered USN is (1RG06cs099) and Sem is (9), which is not in the correct
format. The correct format is 1RG06CS099, & the Sem range is with in (1-8), which is displayed
on the alert box.
Screen 2: Run 2: Entered USN is (1RG06CS099) and Sem is (5). Which is in the correct format.
5. a) Develop and demonstrate, using Javascript script, a XHTML document that contains
Screen 2: The window shows the paragraph when the mouse cursor is placed on it.
Screen 2: The window shows the paragraph when the mouse cursor is placed on it.
Screen 3: The window displays the paragraphs to its original (default) position
b) Create an XSLT style sheet for one student element of the above document and use it
to create a display of that element.
<!DOCTYPE student[
<!ELEMENT student_information (ad+)>
<!ELEMENT ad (usn,name,collegename,branch,year,email)>
<!ELEMENT usn (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT collegename (#PCDATA)>
<!ELEMENT branch (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT label (#PCDATA|email|year|branch|college|name|usn)*>
<!ELEMENT h3 (#PCDATA)>
<!ELEMENT h2 (#PCDATA)>
]>
<h2>Student 2</h2>
<ad><label> usn:<usn> 4bd06499 </usn></label></ad>
<ad><label>Name:<name> BBB </name></label></ad>
<ad><label>College Name:<college> BIET,DVg </college></label></ad>
<ad><label>Branch:<branch> CSE </branch></label></ad>
<ad><label>Year of Joining:<year> 2007 </year></label></ad>
<ad><label>Email -id:<email> [email protected] </email></label></ad>
<h2>Student 3</h2>
<ad><label> usn:<usn> 4bd06499 </usn></label></ad>
<ad><label>Name:<name> CCC </name></label></ad>
</student_information>
xsl.xml
<?xml version = "1.0"?>
<!-- xslplane.xml -->
<?xml-stylesheet type = "text/xsl" href = "xslstudent.xsl" ?>
<student>
<USN> 4bd06cs099 </USN>
<name> Cessna </name>
<college> BIET </college>
<branch>CSE</branch>
<year> 2009 </year>
<email>[email protected]</email>
</student>
xslstudent.xsl
<?xml version = "1.0"?>
<!-- xslplane.xsl -->
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns = "http://www.w3.org/TR/xhtml1/strict">
<xsl:template match = "/">
<h2> Student information </h2>
<span style = "font-style: italic"> USN: </span>
<xsl:value-of select = "student/USN" /> <br />
<span style = "font-style: italic"> Name: </span>
<xsl:value-of select = "student/name" /> <br />
<span style = "font-style: italic"> Branch: </span>
<xsl:value-of select = "student/branch" /> <br />
<span style = "font-style: italic"> college Name: </span>
<xsl:value-of select = "student/college" /> <br />
<span style = "font-style: italic"> Year of Joining: </span>
<xsl:value-of select = "student/year" /> <br />
<span style = "font-style: italic"> Email-id: </span>
<xsl:value-of select = "student/email" /> <br />
</xsl:template>
</xsl:stylesheet>
7a.cgi
#!/usr/bin/perl
print "content-type:text/html \n\n";
print <<END;
<html>
<body bgcolor="aabbcc">
<h3> Perl Program to get the Server-Information</h3>
Server Name: $ENV{'SERVER_NAME'}<br>
Server Port: $ENV{'SERVER_PORT'}<br>
Server Software: $ENV{'SERVER_SOFTWARE'}<br>
Server Protocol: $ENV{'SERVER_PROTOCOL'}<br>
CGI VERSION: $ENV{'GATEWAY_INTERFACE'}
</body>
</html>
END
7b.html
<html>
<head><title>UNIX COMMANDS</title></head>
<body bgcolor="aabbcc">
<h3>ENTER UNIX COMMANDS</h3>
<form action="/cgi-bin/7b.cgi" method="post">
Comand:<input type="text" name="cmd" size=40>
</br>
</br>
<input type="submit" value="Submit">
</form>
</body>
</html>
7b.cgi
#!/usr/bin/perl
use CGI':standard';
print"Content-type:text/html\n\n";
print "<html><body bgcolor=aabbcc>
<h3>Output for the Entered Command</h3>
</body>
</html>";
$cmd=param("cmd");
if($cmd)
{
@result = `$cmd`;
print "<br>";
foreach(@result)
{
print "$_ <br>\t";
}
}
else
{
print "Please give command!!";
}
Screen 1: The browser window is displayed with the text box to enter the Commands.
8a.html
<html>
<head><title>NAME</title></head>
<body bgcolor="aabbcc">
<h3>ENTER NAME & RECEIVE THE GREETINGS</h3>
<form action="/cgi-bin/8a.cgi" method="get">
NAME:<input type="text" name="name"><br/><br/>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
8a.cgi
#!/usr/bin/perl
use CGI':standard';
print "content-type:text/html","\n\n";
$input=param(name);
print "<html><body bgcolor=aabbcc><h3>Hi,$input</h3>";
my @msgs=("Good","Welcome","Fine","Hello");
print "<h3>The message received is: ";
print $msgs[int rand scalar @msgs];
print "</h3></body></html>";
Screen 1: The browser window is displayed with the text box to enter the name .
Screen 2: The browser window displays the name entered and the message which is picked
randomly.
8b.pl
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
print $cgi->header;
print $cgi->start_html('Program 8b');
#print $cgi->start_body('<color=aabbcc>');
print $cgi->h3('<center><font color=green>Server Page Visited
Information</font>
</center>');
#print $cgi->hr;
$count_file="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 "<h3>Welcome User,</h3>";
print "<h3>This page has been visited<font color=red size=8> $no_accesses
</font> times from the creation</h3>";
#print $cgi->end_body;
print $cgi->end_html;
8b.html
<html>
<head><title>VISITORS</title></head>
<body bgcolor="aabbcc">
<br/>
<h3>TO KNOW THE NO. OF VISITORS FOR THIS WEB PAGE</h3>
<form action="/cgi-bin/8b.pl" method="get">
<input type="submit" value="submit">
</form>
</body>
</html>
count.txt
Screen 1: The window gives the option to see the number of visitors to this web page on clicking
the submit button.
Screen 2: The user can see the number of visitors to this web page.
9.cgi
#!/usr/bin/perl
$GS="/usr/bin/gs";
$|=1;
$ds=1;
print "Refresh:",$ds,"\n";
print "content-type:image/png","\n\n";
my ($s,$m,$h)=localtime(time);
$t=sprintf("%02d:%02d:%02d",$h,$m,$s);
open(GS,"|gs -sDEVICE=png256 -sOutputFile=- -q -g200x50 - 2>/dev/null");
print GS <<end;
%!PS -Adobe-3.0 ESPF-3.0
%%BoundingBox:$x $y
%%EndComments
/Arial findfont 20 scalefont setfont
/fontColor {1.0 0.2 0.4 setrgbcolor}def
/bgColor {1.5 0.2 1.0 setrgbcolor}def
/bgColor clippath fill
40 20 moveto
($t)fontColor show
showpage
end
close(GS);
exit(0);
10.html
<html>
<head><title>Age Information</title></head>
<body bgcolor="aabbcc">
<h2>Age Infornmation</h2>
<form action="/cgi-bin/10.cgi" method="get">
<table border="0">
<tr><td>First Name:</td>
<td><input type="text" name="fname"></td>
</tr>
<tr><td>Last Name:</td>
<td><input type="text" name="lname"></td>
</tr>
<tr><td>Age:</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td><input type="submit" value="Submit Form"></td>
<td><input type="reset" value="Reset"></td
</tr>
</table>
</form>
</body>
</html>
10.cgi
#!/usr/bin/perl
use DBI;
use CGI':standard';
print "content-type:text/html","\n\n";
$lname = param("lname") or die "enter lanme";
$fname=param("fname")or die "enter name" ;
$age = param("age")or die "enter age";
$dbh = DBI->connect('DBI:mysql:people','root')
or die("Cannot Connect");
$sth = $dbh->prepare('insert into age_info values(?,?,?)')
or die("Cannot prepare:");
$sth->execute($lname,$fname,$age);
$sth = $dbh->prepare('select * from age_info')
or die("Cannot People");
$sth->execute();
print "<html>";
print "<head><title>Age Info</title></head>";
print "<body bgcolor='aabbcc'>";
print "<h3> contents of age_info table</h3>";
print "<table border='1'>";
print "<tr><th>LNAME</th><th>FNAME</th><th>AGE</th></tr>";
while(($ln,$fn,$age)=$sth->fetchrow())
{
print "<tr><td>$ln</td><td>$fn</td><td>$age</td></tr>";
}
print "</table></body></html>";
Screen 1: The window is displayed with the text box to enter the Name and Age of the user.
Screen 2: The window shows the table details with the updated values.
11.php
<?php
?>
11:Output that the displays the ‘Last visited on’ the web page created.
12.php
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
?>
12:Output that stores page views & increments the count on each refresh.
13. Create a XHTML form with Name, Address Line1, Address Line2, and E-mail text
fields. On submitting, store the values in MYSQL table. Retrieve and display the data
based on Name.
<? Php
$name=$HTTP_POST_VARS["name"];
$add1=$HTTP_POST_VARS["add1"];
$add2=$HTTP_POST_VARS["add2"];
$email=$HTTP_POST_VARS["email"];
<html>
<head><title>PHP and MYSQL</title></head>
<body bgcolor="aabbcc">
<h3>Page to display the Stored data</h3>
<table border="1">
<tr>
<th>NAME</th>
<th>ADDRESS Line1</th>
<th>ADDRESS Line2</th>
<th>EMAIL-id</th></tr>
<?while($array=mysql_fetch_row($result)):?>
<tr>
<td><?echo $array[0];?></td>
<td><?echo $array[1];?></td>
<td><?echo $array[2];?></td>
<td><?echo $array[3];?></td>
</tr>
<? endwhile;?>
<?mysql_free_result($result);?>
<?mysql_close($mysql);?>
</table>
</body>
</html>
<?
$search = $HTTP_POST_VARS["search"];
$mysql = mysql_connect("localhost","root")
or die("Cannot Connect");
mysql_select_db("cus_info")
or die("Cannot select the database");
$result =mysql_query("select * from address where name like '%$search%'")
or die ("cannot execute");
?>
13b.php(To make the search based on the name entered in the table)
<?
$search = $HTTP_POST_VARS["search"];
$mysql = mysql_connect("localhost","root")or die("Cannot Connect");
mysql_select_db("cus_info") or die("Cannot select the database");
$result =mysql_query("select * from address where name like
'%$search%'")or die ("cannot execute");
?>
<html>
<body bgcolor="aabbcc">
13:Output to collect the user information & displays the stored results.
Screen 1: The window gives the option to enter the user information.
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
$mysql=mysql_connect("localhost","root")
or die("can't connect");
mysql_select_db("books")
or die("can't select");
mysql_query("insert into book_info
values('$isbn','$title','$author','$edition','$publication')")
or die("query failed to insert");
$result=mysql_query("select * from book_info");
?>
<html>
<head><title>PHP and MYSQL</title></head>
<body bgcolor="aabbcc">
<table border="1">
<tr>
<th>ISBN</th>
<th>TITLE</th>
<th>AUTHOR</th>
<th>EDITION</th>
<th>PUBLICATION</th>
</tr>
<?while($array=mysql_fetch_row($result)):?>
<tr>
<td><?echo $array[0];?></td>
<td><?echo $array[1];?></td>
<td><?echo $array[2];?></td>
<td><?echo $array[3];?></td>
<td><?echo $array[4];?></td>
</tr>
<? endwhile;?>
<?mysql_free_result($result);?>
<?mysql_close($mysql);?>
</table>
</body>
</html>
14b.php(To search for the book with the title specified by the user)
<?
$search = $HTTP_POST_VARS["search"];
$mysql = mysql_connect("localhost","root")or die("Cannot Connect");
mysql_select_db("books") or die("Cannot select the database");
$result =mysql_query("select * from book_info where title like
'%$search%'") or die ("cannot execute");
14:Output to collect the user information & displays the stored results.
Screen 1: