WEB Programming Laboratory Manual BSC 6 Sem: Web Design Lab HTML
WEB Programming Laboratory Manual BSC 6 Sem: Web Design Lab HTML
WEB Programming Laboratory Manual BSC 6 Sem: Web Design Lab HTML
WEB Programming
LABORATORY MANUAL
1
Web Design Lab HTML
1. Write java program to demonstrate key events by using Delegation event model
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
addKeyListener(this);
showStatus("Key Down");
showStatus("Key Up");
}
2
Web Design Lab HTML
// Display keystrokes.
g.drawString(msg, X, Y);
3
Web Design Lab HTML
2. Write an java program to implement mouse events like mouse pressed, mouse released and
mouse moved by means of an adaptor classes.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
String msg="";
int mousex=0,mousey=0;
addMouseListener(this);
addMouseMotionListener(this);
mousex=0;
mousey=10;
msg="mouse clicked";
repaint();
mousex=0;
mousey=10;
msg="mouse entered";
repaint();
mousex=0;
mousey=10;
msg="mouse exited";
repaint();
mousex=me.getX();
mousey=me.getY();
msg="down";
repaint();
mousex=me.getX();
mousey=me.getY();
msg="up";
repaint();
5
Web Design Lab HTML
mousex=me.getX();
mousey=me.getY();
msg="*";
repaint();
g.drawString(msg,mousex,mousey);
6
Web Design Lab HTML
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
Label l1,l2;
TextField t1,t2;
Button b1;
public WindowListenerTest()
setLayout(new GridLayout(4,2));
l1=new Label("Name");
l2=new Label("Password");
t1=new TextField(10);
t2=new TextField(10);
t2.setEchoChar('*');
b1=new Button("Send");
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
addWindowListener(this);
7
Web Design Lab HTML
d.setSize(400,400);
d.setVisible(true);
this.setVisible(false);
System.exit(0);
8
Web Design Lab HTML
P3.html
<html>
<body>
</body>
</html>
Run p3.html
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*
*/
9
Web Design Lab HTML
ForegroundBackgroundColor.setSize(420, 180);
ForegroundBackgroundColor.add(ColorApplet);
ForegroundBackgroundColor.setVisible(true);
ForegroundBackgroundColor.addWindowListener(new WindowAdapter() {
System.exit(0);
});
{
Color c = getForeground();
setBackground(Color.yellow);
setForeground(Color.red);
g.drawString("hello", 100, 50); // Drawing texts on the graphics screen:
g.drawString("Good Morning", 50, 100);
5.Write an applet that computes the payment of loan based on the amount of the loan,interest
rate and number of months
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Loan" width=300 height=300>
</applet>
10
Web Design Lab HTML
*/
public class Loan extends Applet
implements ActionListener,ItemListener
{
double p,r,n,total,i;
String param1;
boolean month;
Label l1,l2,l3,l4;
TextField t1,t2,t3,t4;
Button b1,b2;
CheckboxGroup cbg;
Checkbox c1,c2;
String str;
public void init()
{
l1=new Label("Balance Amount",Label.LEFT);
l2=new Label("Number of Months",Label.LEFT);
l3=new Label("Interest Rate",Label.LEFT);
l4=new Label("Total Payment",Label.LEFT);
t1=new TextField(5);
t2=new TextField(5);
t3=new TextField(15);
t4=new TextField(20);
b1=new Button("OK");
b2=new Button("Delete");
cbg=new CheckboxGroup();
c1=new Checkbox("Month Rate",cbg,true);
c2=new Checkbox("Annual Rate",cbg,true);
t1.addActionListener(this);
t2.addActionListener(this);
t3.addActionListener(this);
t4.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
c1.addItemListener(this);
c2.addItemListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(c1);
add(c2);
add(b1);
add(b2);
}
public void itemStateChanged(ItemEvent ie)
11
Web Design Lab HTML
{
}
public void actionPerformed(ActionEvent ae)
{
str=ae.getActionCommand();
if(str.equals("OK"))
{
p=Double.parseDouble(t1.getText());
n=Double.parseDouble(t2.getText());
r=Double.parseDouble(t3.getText());
if(c2.getState())
{
n=n/12;
}
i=(p*n*r)/100;
total=p+i;
t4.setText(" "+total);
}
else if(str.equals("Delete"))
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}
}
6. Write an applet to perform the 4 basic arithmetic operations as buttons in a form accepting
two integers in textboxes and display the result.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Applet5" width=300 height=300>
</applet>
*/
12
Web Design Lab HTML
String whichButtonClk;
System.out.println("Initializing an applet");
b1 = new Button("Add");
b3 = new Button("Multiply");
add(label1);
add(tf1);
add(label2);
add(tf2);
13
Web Design Lab HTML
add(b1);
add(b2);
add(b3);
add(b4);
if(ae.getActionCommand().equals("Add") || ae.getActionCommand().equals("Subtract") ||
ae.getActionCommand().equals("Multiply") ||ae.getActionCommand().equals("Divide"))//
checking if an event of clicking the add/subtract/multiply/divide button is generated
repaint();
else
int subtract=i1-i2;
int multiply=i1*i2;
float divide=(float)i1/(float)i2;
if(whichButtonClk.equals("Add"))
if(whichButtonClk.equals("Subtract"))
if(whichButtonClk.equals("Multiply"))
if(whichButtonClk.equals("Divide"))
15
Web Design Lab HTML
<html>
<head>
<title> body and pre tag </title>
</head>
<body text="red" bgcolor="yellow" background="Desert.jpg"> This is an
Illustration of body tag with its properties
<pre>
This text uses
pre tag and preserves
nextline and spaces </pre>
16
Web Design Lab HTML
<html>
<title>Font tag Example</title>
<body>
<font face="arial" size="1" color="blue">WELCOME </font> <br>
<font size="2" color="cyan">WELCOME</font><br>
<font size="3" color="red">WELCOME</font><br>
<font size="4" color="yellow">WELCOME</font><br>
<font size="5" color="green">WELCOME</font><br>
<font size="6" color="brown">WELCOME</font><br>
<font size="7" color="pink">WELCOME</font><br>
<font size="20" color="gray">WELCOME</font><br>
</body>
</html>
OUTPUT
17
Web Design Lab HTML
<html>
<head>
<title> Illustrating comment, h1...h6 and div tags </title>
</head>
<body>
<div style="color:#00ff00">
<h1 align="center"> This is h1 tag text with center aligned </h1>
<h2 align="left"> This is h2 tag text with left aligned </h2>
<h3 align="right">This is h3 tag text with right aligned </h3>
</div>
</body>
</html>
OUTPUT
18
Web Design Lab HTML
<html>
<head>
<title> Text Tags </title>
</head>
<body>
<center>
<h1 align="center">To illustrate text formatting tags </h1>
<hr color="red">
<P> <marquee behavior="alternate"> This is an alternate Marquee text
</marquee>
<p> This is <i> italized </i> </p>
<p> This is <u> underlined </u> </p>
<p> This is <b> bold </b> </p>
<p> This is <em> emphasized </em> </p>
<p>This is <Strong> Strong Text </strong> </p>
<p> This is <s> striked text </s> </p>
<p> This is <code> computer code </code> </p>
<p> This is <sup> superscript </sup> code </p>
<p> This is <sub> subscript </sub> code </p>
<p> This is <big> big text </big> </p>
<p> This is <small> small text </small> </p>
</center>
</body>
</html>
19
Web Design Lab HTML
OUTPUT
20
Web Design Lab HTML
<html>
<head>
<title> Order List tag </title>
</head>
<body>
<h3 align="center" style="color:red">To illustrate ORDER list tags</h3>
<hr COLOR="RED">
<h4>Numbered list:</h4>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
21
Web Design Lab HTML
</ol>
22
Web Design Lab HTML
<html>
<head>
<title> Unorder List </title>
</head>
<body>
<h3 align="center"> To illustrate unorder list tags </h3>
<hr color="red">
</body>
</html>
23
Web Design Lab HTML
OUTPUT
24
Web Design Lab HTML
<html>
<head>
<title> Nested and Definition List </title>
</head>
<body>
<h3 align="center" > To illustrate Nested and Definition List Tags </h3>
<hr color="red">
<h4> An ordered nested List: </h4>
<ol type="a">
<li> Coffee </li>
<li> Tea </li>
<li> Black tea </li>
<li> Green tea </li> </ol>
<ol>
<li> Milk </li>
</ol>
<h4> A Definition List: </h4>
<dl>
<dt> Bangalore </dt>
<dd> -Capital City of Karnataka </dd>
<dt> Mumbai</dt>
<dd> -Capital city of Maharashtra </dd>
</dl>
</body>
</html>
25
Web Design Lab HTML
OUTPUT
26
Web Design Lab HTML
<html>
<head>
<title> Image Tag </title>
</head>
<body>
</body>
</html>
27
Web Design Lab HTML
OUTPUT
28
Web Design Lab HTML
Home.html
<html>
<head>
<title> Link Tag </title>
</head>
<body>
<h3 align="center" style="color:red">To illustrate link Tags</h3> <hr>
Text as a link/hyperlink to another page : <a href="page1.html "> Click here!!!</a>
<hr>
Image as a link/hyperlink :<a href="page1.html">
<img src="desert.jpg" width="32" height="32" align="bottom"/></a>
<hr>
<p>
<a href="#C8">See also Chapter 8 ( link within a page )</a>
</p>
<h2>Chapter 1</h2>
<p>This chapter explains Pointers</p>
<h2>Chapter 2</h2>
<p>This chapter explains variables</p>
<h2>Chapter 3</h2>
<p>This chapter explains operator</p>
<h2>Chapter 4</a></h2>
<p>This chapter explains structure</p>
<h2>Chapter 5</h2>
<p>This chapter explains arrays</p>
<h2>Chapter 6</h2>
<p>This chapter explains linked list</p>
<h2>Chapter 7</h2>
<p>This chapter explains expressions</p>
<h2><a name="C8">Chapter 8</h2>
<p>This chapter explains Binary Trees</p>
<h2>Chapter 9</h2>
<p>This chapter explains Unordered trees</p>
<h2>Chapter 10</h2>
<p>This chapter explains Statements</p>
<h2>Chapter 11</h2>
<p>This chapter explains searching</p>
<h2>Chapter 12</h2>
29
Web Design Lab HTML
</body>
</html>
Page1.html
<html>
<head>
<title> Page1.html </title>
</head>
<body>
<h1 align="center"> Hello!!! This is a new chapter </h1>
<a href="home.html"> Go to home </a>
</body>
</html>
30
Web Design Lab HTML
OUTPUT
31
Web Design Lab HTML
After Clicking on the See also Chapter 8(link within a page) the output is
32
Web Design Lab HTML
<html>
<head>
<title> Table tag </title>
</head>
<body>
<center>
<h4>Table with border, vertical headers, cellpadding and cellspacing</h4>
<table border="10" cellpadding="10" cellspacing="10">
<tr>
<td></td>
<th>Name</th>
<th>Age</th>
<th>Telephone</th>
</tr>
<tr>
<th>Student 1</th>
<td>Radha Desai</td>
<td>20</td>
<td>123 456 789</td>
</tr>
<tr>
<th>Student 2</th>
<td>Geetha Bharadwaj</td>
<td>21</td>
<td>267 891 281</td>
</tr>
</table>
<hr>
<h4>Cell that spans two columns:</h4>
<table border="1">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Radha</td>
<td>555 77 854</td>
<td>555 77 855</td>
33
Web Design Lab HTML
</tr>
</table>
<hr>
<h4>Cell that spans two rows:</h4>
<table border="1">
<tr>
<th>First Name:</th>
<td>Radha</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
</center>
</body>
</html> OUTPUT
34
Web Design Lab HTML
<html> f1.html
<head>
<title> f1.html </title>
</head>
<body>
<h3> Districts of karnataka </h3>
<a href="demo.html" target="main"> gulbarga<br></a>
<a href="demo1.html" target="main"> Belagavi<br> </a>
</body>
</html>
f2.html
<html>
<head>
<title> f2.html </title>
</head>
<body>
<h1> Click on any District to get a welcome message </h2>
</body>
</html>
demo.html
<html>
<head>
<title> demo.html </title>
</head>
<body bgcolor="green">
<h1> Welcome to gulbarga </h1>
35
Web Design Lab HTML
</body>
</html>
Demo1.html
<html>
<head>
<title> belagavi.html </title>
</head>
<body bgcolor="red">
<h1> Welcome to belagavi</h1>
</body> OUTPUT
</html>
36
Web Design Lab HTML
<html>
<head>
<title> form tag </title>
</head>
<body>
<center>
<h3 align="center">To illustrate form based tags</h3> <hr color="red">
<form action="">
<p>This is a text box to enter any text.<input type="text" >
<p>This is a text box to enter password.<input type="password" >
<p>This is a text area to enter large text<textarea> </textarea>
<p>This is a button.<input type="button" Value="Click" >
<p><b><u>Radio Options</u></b><br>
<input type="radio" name="y" checked> yes
<input type="radio" name="n" checked> no </p>
<p><b><u>Checkbox Options</u></b><br>
Sunday<input type="checkbox" checked >
Monday<input type="checkbox" > Tuesday<input
type="checkbox" >
</p>
<p><b><u>Menu driven options </u></b>
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select></p>
</form>
</center>
</body>
</html>
37
Web Design Lab HTML
OUTPUT
38
Web Design Lab HTML
<html>
<head>
<title> span tag </title>
<style type="text/css">
span.blue{ color:lightskyblue; font-weight:bold;}
span.green{ color:darkolivegreen; font-weight:bold;}
</style>
</head>
<body>
<p align="center">
<font size=10>
my mother has <span class="blue"> light blue </span> eyes and my father has
<span class="green"> dark green </span> eyes.
</font>
</p>
</body>
</html>
OUTPUT
39
Web Design Lab HTML
<html>
<head>
<title> css demo </title>
<style type="text/css">
body { background-color:red;}
h1 { color:orange; text-align:center;}
</style>
</head>
<body>
<h1> CSS EXAMPLE </h1>
<p> This is a paragraph </p>
</body>
</html>
OUTPUT
40
Web Design Lab HTML
<video controls>
<source src="wildlife.mp4" >
</video>
</center>
</body>
</html>
OUTPUT
41
Web Design Lab HTML
9. Develop and demonstrate a XHTML document that illustrates the use external style sheet,
ordered list, table, borders, padding, color, and the <span> tag.
// style.css
p,table,li,
{
font-family: "lucida calligraphy", arial, 'sans
serif'; margin-left: 10pt;
}
p { word-spacing: 5px; }
body { background-
color:rgb(200,255,205); } p,li,td
{ font-size: 75%;}
td { padding: 0.5cm; }
th {
text-
align:center;
font-size:
85%;
}
{color:#483d8b;} table
{
border-style: outset;
background-color: rgb(100,255,105);
}
li {list-style-type: lower-
roman;} span
{
color:blue;
42
background- Web Design Lab HTML
color:pink; font-
size: 29pt;
font-style:
italic; font-
weight: bold;
}
<table border="4" width="5%"> <!-- table with name & email -->
<tr>
<tr>
</
tr> </tr>
<tr>
</
tr>
<tr>
</
tr>
<tr>
</
tr>
43
<th Web Design Lab HTML
width="204"
>Name
</th>
<th>Email</
th>
<td
width="204"
>Dr.
HNS</td>
<td>abc@pe
s.edu</td>
<td
width="204"
>Dr.
MKV</td>
<td>xyz@re
diffmail.com
</td>
<td
width="204"
>Dr.
GTR</td>
<td>aaa@ya
hoo.co.in</
td>
<td
width="204"
>Dr.
MVS</td>
<td>bbb@h
otmail.com<
/td>
44
Web Design Lab HTML
</table>
<hr> <!-- horizontal line -->
<ol> <!-- ordered list -->
<li> Gowtham</li>
<li> Gowrav </li>
<li> Gopalakrishna </li>
</ol>
<p>
<span>This is a text.</span> This is a text. This is a text. This is a text. This is a text. This is a text. This is
a text. This is a text. This is a text. <span>This is a text.</span>
</p>
</body>
</html>
10. Develop and demonstrate a XHTML file that includes Javascript script for the following
problems: a) Input: A number n obtained using prompt Output: The first n Fibonacci numbers
b) Input: A number n obtained using prompt Output: A table of numbers from 1 to n
and their squares using alert
A)
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml/">
<head><title>Fibonacci Series</title> </head>
<body bgcolor="yellow">
<h3 style="text-align:center;color:red"> Program to generate first n
fibonacci numbers </h3>
<script type="text/javascript">
var limit = prompt("Enter the number");
var f1=0; var f2=1;
document.write("<h3>The limit entered is: </h3>",limit,"<br/>");
document.write("<h3>The fibonacci series is: </h3> <br/>");
if(limit == 1)
{
document.write("",f1,"<br/>");
}
if(limit == 2)
{
document.write("",f1,"<br/>");
document.write("",f2,"<br/>");
}
if(limit > 2)
{
document.write("",f1,"<br/>");
45
Web Design Lab HTML
document.write("",f2,"<br/>");
for(i=2;i<limit;i++)
{
f3 = f2+f1;
document.write("",f3,"<br/>");
f1=f2;
f2=f3;
}
}
</script>
</body>
</html>
B)
<?xml version ="1.0" encoding = "utf-8?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background-color:yellow">
res = x * x;
msg = msg + " "+ x + " * "+ x + " = " + res + "\n";
alert(msg);
</script>
46
Web Design Lab HTML
</body>
</html>
11. Develop and demonstrate a XHTML file and JavaScript script that uses functions for the
following problems
12. Parameter: A string Output: The position in the string of the left-most vowel.
13. Parameter: A number Output: The number with its digits in the reverse order.
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
var str = prompt("Enter the Input","");
if(!(isNaN(str)))
{
var num,rev=0,remainder;
num = parseInt(str);
while(num!=0)
{
remainder = num%10;
num = parseInt(num/10);
rev = rev * 10 + remainder;
}
alert("Reverse of "+str+" is "+rev);
}
else
{
str = str.toUpperCase();
}
</script>
</body>
47
Web Design Lab HTML
</html
14. Design an XML document to store information about a student in an engineering college
Affiliated to VTU. The information must include USN, Name, Name of the College, 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.
P14.xml
<?xml version ="1.0" encoding="utf-8"?>
<!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)>]>
<?xml-stylesheet type="text/css" href="stu.css"?>
<student_information>
<h3>Student-Information</h3>
<h2> student 1</h2>
<ad><label> usn:<usn> 4bd06499 </usn></label></ad>
<ad><label> Name:<name> AAA </name></label></ad>
<ad><label> College name:<College> CIT,Gubbi </College></label></ad>
<ad><label> Branch:<branch> CSE </branch></label></ad>
<ad><label> Year of joining:<year> 2006 </year></label></ad>
<ad><label> Email-ID:<email> aaa@gmail.com </email></label></ad>
<h2> student2</h2>
<ad><label> usn:<usn> 4bd06490 </usn></label></ad>
<ad><label> Name:<name> BBB</name></label></ad>
<ad><label> College name:<College> CIT,Gubbi </College></label></ad>
<ad><label> Branch:<branch> CSE </branch></label></ad>
<ad><label> Year of joining:<year> 2006 </year></label></ad>
<ad><label> Email-ID:<email> bbb@gmail.com </email></label></ad>
<h2> student 3</h2>
<ad><label> usn:<usn> 4bd06491 </usn></label></ad>
<ad><label> Name:<name> CCC </name></label></ad>
<ad><label> College name:<College> CIT,Gubbi </College></label></ad>
<ad><label> Branch:<branch> CSE </branch></label></ad>
<ad><label> Year of joining:<year> 2006 </year></label></ad>
<ad><label> Email-ID:<email> ccc@gmail.com </email></label></ad>
</student_information>
48
Web Design Lab HTML
Stu.css
15. Write a Perl program to display various Server Information like Server Name, Server
Software, Server protocol, CGI Revision etc.
#!/usr/bin/perl
"<html>",
"<h1>Welcome to CIT</h1>",
"<body>",
49
Web Design Lab HTML
"</html>";
16. Write a Perl program to accept UNIX command from a HTML form and to display the
output of the command executed
#!/usr/bin/perl
use CGI':standard';
print header(),
start_html(-title=>'UNIX COMMAND',-bgcolor=>'#00ffff'),
hr(),
startform(-method=>'get',-action=>'./lab5b.cgi'),
textfield(-name=>'cmd'),br(),
br(),
submit(-value=>'EXECUTE'),
endform(),
hr(),
'$',$cmd=param("cmd"),
br(),
pre(`$cmd`),
end_html();
50
Web Design Lab HTML
17. 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
#!/usr/bin/perl
print header(),
start_html(-bgcolor=>‟lightyellow‟),
hr,
br,
wc –l`),
br,
font({-color=>‟lightblue‟,-size=>‟4‟},‟no of times‟),
br,
hr,
end_html;
51
Web Design Lab HTML
18. 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
#!/usr/bin/perl
use CGI':standard';
use DBI;
$sth = $dbh->prepare („insert into userinfo values (?,?)”) or die “can not insert”.$dbh->errstr();
print header(),
start_html(-title=>'database access',-bgcolor=>'#00ffff'),
h1({-align=>'center'},'Database Access'),
hr(),
h2({-align=>'center'},'Database insert'),
start_form(-action=>’./8.cgi’),
‘NAME:’,
textfield(-name=>’name’),
br,
‘AGE:’
52
Web Design Lab HTML
textfield(-name=>’age’),
br,
submit (-value=>’Insert’),
reset (-value=>’Reset’),
end_form(), hr();
$ename = param(‘name’);
$eage = param(‘age’);
if ($ename eq “ ”)
else
print hr(),
h2({-align=>'center'},'Database display'),
pre(
‘userinfo’
br(),
‘-‘x 50,br(), ‘
NAME AGE’,br(),
‘-‘x 50);
$st1->execute();
while(($ename,$eage)=$sth1->fetchrow())
{
53
Web Design Lab HTML
$sth1->finish();
$sth->finish();
$dbh->disconnect;
end_html();
54