0% found this document useful (0 votes)
348 views68 pages

WT Lab

The document describes a form created with frames to display different HTML pages. The form has two frames - one at the top to hold navigation links, and a larger frame below to display page content. The navigation links frame contains 5 links to different HTML files that are displayed in the main frame when clicked. Sample code is provided for the main form page and some of the individual content pages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
348 views68 pages

WT Lab

The document describes a form created with frames to display different HTML pages. The form has two frames - one at the top to hold navigation links, and a larger frame below to display page content. The navigation links frame contains 5 links to different HTML files that are displayed in the main frame when clicked. Sample code is provided for the main form page and some of the individual content pages.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 68

ACHARAYA NAGARJUNA UNIVERSITY

DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

CERTFICATE

This is to certify that____________________ is a student of MCA with


Redg.no_____________________ has satisfactorily completed the practical
work on Web Technologies during the academic year 2020-2021

Lecturer-In-charge Head of the Department

External Examiner

INDEX
S.NO NAME OF THE PROGRAM PAGE
NO
1 Develop and demonstrate a HTML document that illustrates the
use external style sheet, ordered list, table, borders, padding, color,
and the <span> tag.
2 Write HTML code to provide intra document linking.
3 Create a form with the following specifications :
a). Our form uses frames, one to hold the links bar at the top of the
browser window.
b). Other is a larger frame that provides the main view.
c). The links bar should contain 3 links, which when clicked,
should display the appropriate HTML file in the larger frame.
4 To Create a webpage with the following using html
a. To embed an image in web page
b. To fix the hot spots
c. Show all the related information when a hot spot is clicked in the
map.
5 Develop a HTML Form,which accepts any Mathematical
expression. Write JavaScript code to Evaluates the expression and
Displays the result
6 Create a HTML form that has number of Textboxes. When the
form runs in the Browser fill the textboxes with data. Write
JavaScript code that verifies that all textboxes has been filled. If a
textboxes has been left empty, popup an alert indicating which
textbox has been left empty
7 Write a JavaScript code to find the sum of N natural Numbers.(Use
user-defined function)
8 Write a JavaScript code to find factorial of N. (Use Recursive
Function)

9 Write a JavaScript code block using arrays and generates the


current date in words, this should include the day, month and year.

10 Create a web page using two image files, which switch between
one another as the mouse pointer moves over the images. Use the
onMouseOver and onMouseOut event handlers.
11 Design an XML document to store information about a student in
an engineering college affiliated to ANU. The information must
include college id, Name of the College, Brach, 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.
12 Create an XML document, which contains 10 users information.
Implement a program, which takes User Id as an input and returns
the user details by taking the user information from the XML
document.
13 Write a program for implementing student information using xml.
14 Write a java program to illustrate java to database connectivity
using JDBC

15 Write a program to print the Fibonacci numbers using RMI.


16 Write a program using RMI to access the database using the
primary key value and return the data to the client.
17 Write a html program for invoking servlet from applet.
18 write a java servlet program to conduct online examination and to
display student mark list available in a database.
19 Create a java program to create an airline reservation service and a
travel agent and the travel agent is searching for an airline using
web services and database.

20 Write a JSP program to calculate income tax, login and data


capture.

1. Develop and demonstrate a HTML document that illustrates the use


external style sheet, ordered list, table, borders, padding, color, and the
<span> tag.

1a.html :
<html>
<head>
<link rel="stylesheet" type="text/css" href="1b.css"/>
<title>Lab Program1</title>
</head>
<body id="div">
<h1>This header is 50 pt</h1>
<h1>This header is green</h1>
<p>This paragraph has a left margin of 60 pixels</p>
<table cellpadding="20" border="1" width="7%"><!-- table with name & email
-->
<tr>
<th width="210">Name</th>
<th>Email</th>
<th>Mobile</th>
</tr>
<tr>
<td width="210">Mahendra</td>
<td>paladugu.mahendra@gmail.com</td>
<td>8712345927</td>
</tr>
<tr>
<td width="210">Surendra</td>
<td>surendrasuri45@rediffmail.com</td>
<td>8500245229</td>
</tr>
<tr>
<td width="210">Ram Mohan</td>
<td>yanumularammohan661@yahoo.com</td>
<td>8500614589</td>
</tr>
</table>
<hr><!--horizontal line -->
<ol><!--ordered list-->
<li>Mahendra</li>
<li>Surendra</li>
<li>Mohan</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>
1b.css :
#tablediv{ color:Aqua;
background-color:green;
}

Output :

2. Write HTML code to provide intra document linking.


<html>
<head>
<title> Java </title>
</head>
<body text=navy>
<h1><center>Java</h1></center>
<hr>
<a name=home></a>
<ul>
<li><a href="#intro">Introduction</a></li>
<li><a href="#hist">History</a></li>
<li><a href="#Feat">Java Features</a></li>
<li><a href="#dt">Datatypes</a></li>
</ul>
<hr>
<b><a name="intro">INTRODUCTION</a></b>
<p>
Java is a platform independent, object oriented programming language, which is
used to develop different types of applications like:
<ul>
<li>Desktop Applications</li>
<li>Web Applications</li>
<li>Enterprise Applications</li>
<li>Mobile Applications</li>
<li>Applications for Embedded Systems</li>
<li>Applications for Smart Card</li>
<li>Applications for Robotics</li>
<li>And Many more....</li>
</ul>
</p>
<b><a name="hist">HISTORY</a></b>
<li>1.In 1991,a small group of Sun engineers (James Gosling,Mike Sheridan, and
Patrick Naughton)called "Green Team"led by James Gosling invented Java.</li>
<li>2. The initial name of java is "oak".</li>
<li>3.On January 27,2010 Java was merged into the Oracle Corporation.</li>
</ul>
<b><a name="Feat">Java Features</a></b>
<ul>
<li>1.Compiled and Interpreted Programming Language</li>
<li>2.Platform Inedpendence</li>
<li>3.Object Oriented</li>
<li>4.Distributed and Network Supported</li>
<li>5.Robust</li>
</ul>
<b><a name="dt">Datatypes</a></b>
<p>
<ul>
<li>Primitive Datatypes</li>
<li>Reference\Object Datatypes</li>
</ul>
</p>
<br><br><b><a href="#home">Top</a></b>
</body>
</html>

Output :
3. Create a form with the following specifications :
a). Our form uses frames, one to hold the links bar at the top of the
browser window.
b). Other is a larger frame that provides the main view.
c). The links bar should contain 5 links, which when clicked, should
display the appropriate HTML file in the larger frame.
framedemo.html :
<frameset rows="25%,75%">
<frame src=logo.html scrolling=no resize frameborder=0>
<frameset cols="10%,90%">
<frame src=lang.html noresizeframeborder=0>
<frame src=aboutme.html name=f frameborder=0>
</frameset>
</frameset>
aboutme.html :
<html>
<body background="bkgnd2.jpg" text=Aqua>
<table border=0 width=40% color=Aqua align=left
<tr>
<td colspan=2>
<h1><center><font color=green>About Me</h1></center></font></td>
</tr>
<tr>
<td width=16%><imgsrc="mahilogo2.jpg"></td>
<td><font color=black><b>P.MahendraBabu<br>
STUDENT<br>
Department of Computer Science and Engineering,<br>
Acharya Nagarjuna University,<br>
Nagarjuna Nagar, Guntur.<br>
Phone : 8712345927<br>
E-mail: paladugu.mahendra@gmail.com<br></b></font>
</td>
</tr>
</table>
</body>
</html>
logo.html :
<html>
<body bgcolor=#8080ff>
<table border=0 width=100%>
<tr>
<td rowspan=2 width=8%><imgsrc="bkgnd1.jpg" width=150 height=150></td>
<td><font size=8 color=navy><b><center>Mahendra InfoTech</font></b><br>
<font color=darkred size=5><b>A Complete reference of
Technology</font></b></td>
</tr>
<tr>
<td><marquee behavior=alternate direction=left><h2><font color=yellow>The
inexhaustible
vessel</font></h2></marquee><br></center></td>
</tr>
</table>
</body>
</html>
lang.html :
<html>
<head>
<title>Welcome</title>
</head>
<body bgcolor=peachpuff text=maroon>
<h3><a href="c.html" target=f>C</a></h3>
<h3><a href="cpp.html" target=f>C++</a></h3>
<h3><a href="java.html" target=f>JAVA</a></h3>
<h3><a href="ht.html" target=f>HTML</a></h3>
<h3><a href="jsct.html" target=f>JavaScript</a></h3>
<h3><a href="aboutme.html" target=f>Home</a></h3>
</body>
</html>
java.html :
<html>
<head>
<title> Java </title>
</head>
<body text=navy>
<h1><center>Java</h1></center>
<hr>
<a name=home></a>
<ul>
<li><a href="#intro">Introduction</a></li>
<li><a href="#hist">History</a></li>
<li><a href="#Feat">Java Features</a></li>
<li><a href="#dt">Datatypes</a></li>
</ul>
<hr>
<b><a name="intro">INTRODUCTION</a></b>
<p>
Java is a platform independent, object oriented programming language, which is
used to develop different types of applications like:
<ul>
<li>Desktop Applications</li>
<li>Web Applications</li>
<li>Enterprise Applications</li>
<li>Mobile Applications</li>
<li>Applications for Embedded Systems</li>
<li>Applications for Smart Card</li>
<li>Applications for Robotics</li>
<li>And Many more....</li>
</ul>
</p>
<b><a name="hist">HISTORY</a></b>
<li>1.In 1991,a small group of Sun engineers (James Gosling,Mike Sheridan, and
Patrick Naughton)called "Green Team"led by James Gosling invented Java.</li>
<li>2. The initial name of java is "oak".</li>
<li>3.On January 27,2010 Java was merged into the Oracle Corporation.</li>
</ul>
<b><a name="Feat">Java Features</a></b>
<ul>
<li>1.Compiled and Interpreted Programming Language</li>
<li>2.Platform Inedpendence</li>
<li>3.Object Oriented</li>
<li>4.Distributed and Network Supported</li>
<li>5.Robust</li>
</ul>
<b><a name="dt">Datatypes</a></b>
<p>
<ul>
<li>Primitive Datatypes</li>
<li>Reference\Object Datatypes</li>
</ul>
</p>
<br><br><b><a href="#home">Top</a></b>
</body>
</html>

ht.html :
<html>
<head>
<body bgcolor=#00ffff text=blue>
<center><h1>HTML</h1></center>
<p>
<ul>
<li>HTML stands for "Hyper Text Mark-up Language"</li>
<li>HTML is the bricks and mortar of the WWW.</li>
<li>Without HTML the World Wide Web could not have become as important as
it is today.</li>
<li>HTML is a document formatting language common the all computerso the
WWW.</li>
<li>HTML permits cross platform communication between
Macs,Apples,SUNs,PCs and others to view a document in a similar way.</li>
<li>HTML has two sections, the "Head" section and the "Body" section</li>
</ul>
</p>
</body>
</html>

Output :
4. To Create a webpage with the following using html
a. To embed an image in web page
b. To fix the hot spots
c. Show all the related information when a hot spot is clicked in the map.

Image.html:

<html>
<head>
<title>
<title>Image Map</title>
</head>
<body><imgsrc="Andhramap.jpg" usemap="#Andhramap" alt="Andhrmap">
<map name="Andhramap">
<area href="Prakasam.html" alt="Prakasam"shape="circle" coords="50,180,120"
title="Prakasam"/>
<area href="Guntur.html" shape="square" coords="" title="Guntur/">
</map>
</body>
</html>

Prakasam.html:

<html>
<head>
<title>About Prakasam</title>
</head>
<body>
<center><h1>Prakasam</h1></center>
<hr>
<ul>
<li>Area : 17,626 Sq.Kms.</li>
<li>Population : 3,397,448</li>
<li>Collector Name : Smt. Sujatha Sharma I.A.S</li>
<li>Mandals : 24 </li>
</ul>
</hr>
<a href="imagemap.html">Andhramap</a>
</body>
</html>
Output:
5. Develop a HTML Form,which accepts any Mathematical expression. Write
JavaScript code to Evaluates the expression and Displays the result.

<html>
<head>
<title>Mathematical Expression</title>
<script type="text/javascript">
function math_exp()
{
var x=document.form1.exptext.value;
var result=eval(x);
document.form1.resulttext.value=result;
}
</script>
</head>
<body>
<form name="form1">
<table>
<tr>
<td>Expression</td>
<td><input type="text" name="exptext"/></td>
</tr>
<tr>
<td>Result</td>
<td><input type="text" name="resulttext"/></td>
</tr>
<tr>
<td><input type="button" value="calculate" onclick="math_exp()"/></td>
</tr>
</table>
</form>
</body>
</html>
Output :
6. Create a HTML form that has number of Textboxes. When the form runs
in the Browser fill the textboxes with data. Write JavaScript code that verifies
that all textboxes has been filled. If a textboxes has been left empty, popup an
alert indicating which textbox has been left empty.

<html>
<head>
<title>Registration Form</title>
<script type="text/javascript">
function validate()
{
if(document.myForm.Name.value=="")
{
alert("Please Provide Your Name");
document.myForm.Name.focus();
return false;
}
if(document.myForm.Email.value=="")
{
alert("Please Provide Your Email ID");
document.myForm.Email.focus();
return false;
}
if((document.myform.Zip.value=="")||(document.myForm.Zip.value.length!
=5))
{
alert("Please Provide a valid zip code format #####");
document.myForm.Zip.focus();
return false;
}
if(document.myForm.Country.value=="-1")
{
alert("Please Provide Your Country Name");
return false;
}
return true;
}
function validateEmail()
{
varemailID=document.myForm.Email.value;
atpos=emailId.indexOf("@");
dotpos=emailID.lastIndexOf(".");
if(atpos<1||(dotpos-atpos<2))
{
alert("Please Enter Correct Email ID");
document.myForm.Email.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return(validate());">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>Name</td>
<td><input type="text" name="Email" onchange="validateEmail();"/></td>
</tr>
<tr>
<td>Zip Code</td>
<td><input type="text" name="Zip"/></td>
</tr>
<tr>
<td>Country</td>
<td><select name="Country">
<option value="-1" selected>[Choose Yours]</option>
<option value="1">INDIA</option>
<option value="2">USA</option>
<option value="3">Srilanka</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
</body>
</html>
Output :
7. Write a JavaScript code to find the sum of N natural Numbers.(Use user-
defined function)
<html>
<head>
<script type="text/javascript">
varnum=window.prompt("Enter the number:","");
var n=parseInt(num);
result=sumnaturalno(n);
window.alert("The sum of "+n+"natural number is"+result);
function sumnaturalno(n)
{
vari;
var sum=0;
for(i=1;i<=n;i++)
{
sum=sum+i;
}
return(sum);
}
</script>
</head>
</html>
Output :
8. Write a JavaScript code to find factorial of N. (Use Recursive Function)
<html>
<body>
<script type="text/javascript">
var n=parseInt(window.prompt("Enter the Number:"));
var result=fact(n);
window.alert("Factorial of the given number"+result);
function fact(n)
{
if(n==0)
return 1;
else
return(n*fact(n-1));
}
</script>
</body>
</html>
Output :
9. Write a JavaScript code block using arrays and generates the current date
in words, this should include the day, month and year.

<html>
<head>
<script type="text/javascript">
var d=new Date();
var weekday=new
Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturda
y");
varmonthname=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec
");
document.write(weekday[d.getDay()]+"");
document.write(d.getDate()+".");
document.write(monthname[d.getMonth()]+"");
document.write(d.getFullYear());
</script>
</head>
<body>
</body>
</html>
Output :
10. Create a web page using two image files, which switch between one
another as the mouse pointer moves over the images. Use the onMouseOver
and onMouseOut event handlers.
<html>
<head>
<script type="text/javascript">
function mouseover()
{
document.getElementById("img").src="img.jpg";
}
function mouseout()
{
document.getElementById("img").src=img1.jpg;
}
</script>
</head>
<body>
<imgsrc="img2.jpg" id="img" onmouseover="mouseover()"
onmouseout="mouseout()"/>
</body>
</html>
Output :
11. Design an XML document to store information about a student in an
engineering college affiliated to ANU. The information must include college
id, Name of the College, Brach, 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 FILE

<?xml version="1.0" ?>


<!-- Obtain stylesheet. Note that the xml file &css file should be in the same
directory/location -->
<?xml-stylesheet type="text/css" href="4a.css" ?>
<student>
Student 1 details:
<info>
USN:<usn>Y16MC2001</usn>
Name:<name>Surya</name>
College:<coll>College of Sciences</coll>
Branch:<branch>ECE</branch>
Year Of Joining:<yoj>2014</yoj>
Email-ID:<email>abc@samp.com</email>
</info>
Student 2 details:
<info>
USN:<usn>Y16MC20002</usn>
Name:<name>Sri</name>
College:<coll>College of Sciences</coll>
Branch:<branch>CSE</branch>
Year Of Joining:<yoj>2014</yoj>
Email-ID:<email>pqr@samp.com</email>
</info>
Student 3 details:
<info>
USN:<usn>Y1MC20003</usn>
Name:<name>Shourya</name>
College:<coll>College of Sciences</coll>
Branch:<branch>ISE</branch>
Year Of Joining:<yoj>2014</yoj>
Email-ID:<email>xyz@samp.com</email>
</info>
</student>

4a.CSS

student {margin-top:15px;font-weight:bold;color:black;}
info {display:block;margin-left:15px;color:gray;}
usn, name {color:red;font-size:15pt;}
coll, branch {color:blue;font-size:15pt;}
yoj, email {color:green;font-size:15pt;}

output:
12. Create an XML document, which contains 10 users information.
Implement a program, which takes User Id as an input and returns the user
details by taking the user information from the XML document.

Info.xml

/* XML Document which stores info */

<?xml version="1.0" ?>

<document>

<users>

<user>

<userid>abc</userid>

<password>abc</password>

<first_name>raj</first_name>

<last_name>kumar</last_name>

<dob>10/1/1982</dob>

</user>

<user>

<userid>ravi</userid>

<password>ravi</password>

<first_name>ravi</first_name>

<last_name>kumar</last_name>

<dob>11/11/1982</dob>

</user>

<user>
<userid>sri</userid>

<password>sri</password>

<first_name>sri</first_name>

<last_name>ram</last_name>

<dob>12/12/1983</dob>

</user>

<user>

<userid>lax</userid>

<password>lax</password>

<first_name>laxman</first_name>

<last_name>kumar</last_name>

<dob>1/1/1980</dob>

</user>

<user>

<userid>chandu</userid>

<password>chandu</password>

<first_name>chandana</first_name>

<last_name>priya</last_name>

<dob>9/11/1998</dob>

</user>

<user>

<userid>vysu</userid>

<password>vysu</password>
<first_name>vyshnavi</first_name>

<last_name>matha</last_name>

<dob>17/6/1982</dob>

</user>

<user>

<userid>prem</userid>

<password>prem</password>

<first_name>prem</first_name>

<last_name>kumar</last_name>

<dob>11/11/1988</dob>

</user>

<user>

<userid>geeta</userid>

<password>geeta</password>

<first_name>geeta</first_name>

<last_name>anjali</last_name>

<dob>13/1/1972</dob>

</user>

<user>

<userid>preeti</userid>

<password>preeti</password>

<first_name>prethi</first_name>

<last_name>priya</last_name>
<dob>7/11/1968</dob>

</user>

<user>

<userid>praveen</userid>

<password>praveen</password>

<first_name>kumar</first_name>

<last_name>kumar</last_name>

<dob>11/11/1999</dob>

</user>

</users>

</document>

Program:

<html>

<head>

<title>authorization page</title>

<script language="JavaScript" Run At=server>

varxmlDoc=new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.load("C:\Users\satishpolampalli\Desktop\New folder\info.xml");

function search()

var id=document.myform.id.value;

varpword=document.myform.pword.value;
varqry=xmlDoc.selectNodes("document/users/user[userid='"+id+"']");

if(qry.length!=0)

if(pword!=qry.item(0).childNodes.item(1).text)

document.body.innerHTML="Password incorrect";

document.write("success");

else

document.body.innerHTML="No matching data found. userid incorrect";

</script>

</head>

<body>

<pre>

<center>

<form name="myform" method=post action="result.html">

User id:<input type=text name=id><br>

password :<input type=password name=pword><br>

<input type=submit value=Go onClick="search()">

</form>

</center>

</pre>

</body>
</html>

Output:
13. Write a program for implementing student information using xml.
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="i.css"?>
<document>
<student>
<name>Mahendra</name>
<addr>6-1 Kanigiri</addr>
<grade>A</grade>
</student>
<student>
<name>Suraj</name>
<addr>1-1 Kanigiri</addr>
<grade>A</grade>
</student>
<student>
<name>Sarat</name>
<addr>2-1 Kanigiri</addr>
<grade> A </grade>
</student>
</document>
i.css;
student{ font-family:arial;
color: Green;
font-size: 20pt;
}
Output:
14. Write a java program to illustrate java to database connectivity using
JDBC.

import java.sql.*;
import static java.lang.System.*;
class Select2
{ public static void main(String args[])throws Exception
{ Class.forName("oracle.jdbc.driver.OracleDriver");
out.println("Loaded....");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","sc
ott","tiger");
out.println("Connected...");
Statement stmt=con.createStatement();
ResultSetrs=stmt.executeQuery("select * from emp");
while(rs.next())
{ out.print(rs.getString("empno")+"\t"+rs.getString("ename"));
out.println();
}
con.close();
}
}

OUTPUT:

empno ename
1 Mahendra
2 Surendra
3 Suraj
15. Write a program to print the Fibonacci numbers using RMI.

CLIENT PROGRAM:
import java.io.*;
import java.rmi.*;
public class client
{
public static void main(String args[])throws Exception
{
try
{
String s="rmi://"+args[0]+"/abc";
serverint f=(serverint)Naming.lookup("rmi://localhost:5000/sonoo");
DataInputStream m=new DataInputStream(System.in);
int n1=Integer.parseInt(m.readLine());
System.out.println("The factorial is"+f.fact(n1));
}
catch(Exception e)
{
System.out.println(e);
}
}
}

INTERFACE PROGRAM:
import java.rmi.*;
public interface serverint extends Remote
{
int fact(int n)throws Exception;
}

IMPLEMENTATION PROGRAM:
import java.rmi.*;
import java.rmi.server.*;
public class serverimpl extends UnicastRemoteObject implements serverint
{
public serverimpl()throws Exception
{
super();
}
public int fact(int n)
{
inti,c=1;
for(i=1;i<=n;i++)
{
c=i*c;
}
return c;
}
}

SERVER PROGRAM:
import java.rmi.*;
import java.rmi.registry.*;
public class server
{
public static void main(String args[])
{
try
{
serverimpl m=new serverimpl();
Naming.rebind("rmi://localhost:5000/sonoo",m);
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}
OUTPUT:

SERVER WINDOW
c:mahi\32>javac serverint.java
c:mahi\mahi32>javac serverimpl.java
c:\mahi32>javac server.java
c:\mahi32>rmic serverimpl
c:\mahi32>start rmiregistry
c:\mahi32>java server
CLIENT WINDOW:C:\mahi32>javac client.java
C:\mahi32>java client localhost
3
The factorial is 6
16 . Write a program using RMI to access the database using the primary key
value and return the data to the client.

Server Interface:
import java.rmi.*;
import java.sql.*;
import java.util.*;
public interface serverint extends Remote
{
public String jdbc(int n)throws Exception;
}

Server Implementation:
import java.rmi.*;
import java.sql.*;
import java.util.*;
import java.rmi.server.*;
public class serverimpl extends UnicastRemoteObject implements serverint
{
public serverimpl()throws Exception{
}
public String jdbc(int n) throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:PVKR","PVKR","PVKR");
Statement stmt=con.createStatement();
ResultSetrs=stmt.executeQuery("SELECT * FROM emp where
empno="+n);
String s=" ";
while (rs.next()){
s=s+rs.getInt(1)+" ";
s=s+rs.getString(2)+" ";
s=s+rs.getString(3)+" ";
s=s+rs.getInt(4)+" ";
s=s+rs.getDate(5)+" ";
s=s+rs.getDouble(6)+" ";
s=s+rs.getDouble(7)+" ";
s=s+rs.getInt(8)+" ";
}
return s;
}
}

Server:
import java.net.*;
import java.rmi.*;
public class server
{
public static void main(String args[])
{
try
{
serverimpl m=new serverimpl();
Naming.rebind("abc1",m);
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}

Client:
import java.util.*;
import java.sql.*;
import java.io.*;
import java.rmi.*;
public class client
{
public static void main(String args[])throws Exception
{
try
{
String s="rmi://"+args[0]+"/abc1";
serverint f=(serverint)Naming.lookup(s);
DataInputStream m=new DataInputStream(System.in);
System.out.println("Enter empid from emp");
int n1=Integer.parseInt(m.readLine());
String rs=f.jdbc(n1);
System.out.println(rs);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
17. Write a html program for invoking servlet from applet.

MyServer.java:

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class MyServer extends GenericServlet
{
 public void service(ServletRequestreq,ServletResponse res)throws
ServletException,IOException
 {
  PrintWriter pw=res.getWriter();
  Date d=new Date();
  pw.println("<html><body bgcolor=blue><h2>Server Response</h2>");
  pw.println("<h3>Current Date and Time From Server:</h3>");
  pw.println("<b>"+d+"</b></body></html>");
 }
}

web.xml:

<web-app>  
    <servlet>
        <servlet-name>Applet</servlet-name>
        <servlet-class>MyServer</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Applet</servlet-name>
        <url-pattern>/MyServer</url-pattern>
    </servlet-mapping>
</web-app>
AppletClient.java:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class AppletClient extends Applet implements ActionListener
{
 public void init()
 {
  Label la=new Label("INVOKING SERVLET FROM APPLET");
  la.setFont(new Font("Courier",Font.BOLD,15));
  la.setForeground(Color.blue);
  add(la);
  Button b1=new Button("Click Here To Display Date Information From Server");
  b1.setBackground(Color.black);
  b1.setForeground(Color.white);
  add(b1);
  b1.addActionListener(this);
 }
 public void actionPerformed(ActionEvent ae)
 {
  try
  {
   AppletContext ac=getAppletContext();
   URL url = new URL("http://localhost:8080/servlets3/MyServer");
   ac.showDocument(url);
  }
  catch(Exception e)
  {
   System.out.println(e);
  }
 }
}

AppletClient.HTML:

<html>
<head>
<title>Invoking Servlets From Applet</title>
</head>
<body bgcolor="violet">
<applet code="AppletClient.class" width="400" height="200">
</applet>
</body></html>
18. write a java servlet program to conduct online examination and to display
student mark list available in a database

StudentServlet3

import java.io.*;

import java.sql.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class StudentServlet3 extends HttpServlet{String


message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5};

int Total=0;

Connection connect;

Statement stmt=null;

ResultSetrs=null;

public void doPost(HttpServletRequestrequest,HttpServletResponse response)


throwsServletException,IOException

try

String url="jdbc:odbc:NEO";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connect=DriverManager.getConnection(url," "," ");

message="Thank you for participating in online Exam";


}

catch(ClassNotFoundExceptioncnfex)

cnfex.printStackTrace();

catch(SQLExceptionsqlex){sqlex.printStackTrace();}

catch(Exception excp){excp.printStackTrace();}

Seat_no=request.getParameter("Seat_no");

Name=request.getParameter("Name");

ans1=request.getParameter("group1");

ans2=request.getParameter("group2");

ans3=request.getParameter("group3");

ans4=request.getParameter("group4");

ans5=request.getParameter("group5");

if(ans1.equals("True"))Total+=2;

if(ans2.equals("False"))Total+=2;

if(ans3.equals("True"))Total+=2;

if(ans4.equals("False"))Total+=2;

if(ans5.equals("False"))Total+=2;

try{Statement stmt=connect.createStatement();

Stringquery="INSERT INTO student("+"Seat_no,Name,Total"+") VALUES


('"+Seat_no+"','" + Name+"', '"+Total+"')";

int result=stmt.executeUpdate(query);
stmt.close();}

catch(SQLException ex){}response.setContentType("text/html");

PrintWriter out=response.getWriter();out.println("<html>");

out.println("<head>");

out.println("</head>");

out.println("<body bgcolor=cyan>");

out.println("<center>");

out.println("<h1>"+message+"</h1>\n");

out.println("<h3>Yours results stored in our database</h3>");

out.print("<br><br>");

out.println("<b>"+"Participants and their Marks"+"</b>");

out.println("<table border=5>");

try

Statement stmt=connect.createStatement();

String query="SELECT * FROM student";

rs=stmt.executeQuery(query);

out.println("<th>"+"Seat_no"+"</th>");

out.println("<th>"+"Name"+"</th>");

out.println("<th>"+"Marks"+"</th>");

while(rs.next()){out.println("<tr>");

out.print("<td>"+rs.getInt(1)+"</td>");

out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");

out.println("</tr>");}out.println("</table>");

catch(SQLException ex){ }

finally

try

if(rs!=null)rs.close();

if(stmt!=null)stmt.close();

if(connect!=null)connect.close();

catch(SQLException e)

{}

out.println("</center>");out.println("</body></html>");Total=0;}

Html Code:

<html>

<head>

<title>Database Test</title>

</head>
<body><center><h1>Online Examination</h1></center>

<form action="StudentServlet3.view" method="POST">

<div align="left"><br></div><b>Seat Number:</b>

<input type="text" name="Seat_no"><div align="Right"><b>Name:</b><input


type="text" name="Name" size="50"><br></div>

<br><br><b>1. Every host implements transport layer.</b><br/>

<input type="radio" name="group1" value="True">True<input type="radio"


name="group1" value="False">False<br>

<b>2. It is a network layer's responsibility to forward packets reliably from source


todestination</b><br/>

<input type="radio" name="group2" value="True">True<input type="radio"


name="group2" value="False">False<br>

<b>3. Packet switching is more useful in bursty traffic</b><br/>

<input type="radio" name="group3" value="True">True<input type="radio"


name="group3" value="False">False<br>

<b>4. A phone network uses packet switching</b><br/><input type="radio"


name="group4" value="True">True

<input type="radio" name="group4" value="False">False<br><b>5. HTML is a


Protocol for describing web contents</b><br/>

<input type="radio" name="group5" value="True">True<input type="radio"


name="group5" value="False">False<br><br>

<br><br><center><input type="submit" value="Submit"><br><br></center>

</form>

</body>

</html/>
Output:
19. Create a java program to create an airline reservation service and a travel
agent and the travel agent is searching for an airline using web services and
database.

<?xml version = "1.0"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Solution11.16 -->

<!-- Airline Reservation System-->

<html xmlns = "http://www.w3.org/1999/xhtml">

<head>

<title>Airline Reservation System</title>

<script type = "text/javascript">

var input;

varsecondInput;

var element;

varsecondElement;

varfirstCount = 0;

vareconomyCount = 0;

var seats = [1,2,3,4,5,6,7,8,9,10]; //allocate 10-element Array function

startArray()

for(vari=0; i<11; i++)

{
input = window.prompt("Please type 1 for First Class and Please type 2 for
Economy.","0");

if (input == 1 || input == 2)

element = linearSearch(seats);

if(element == -1 && input == 1)

document.writeln("The First Class is already fully booked<br/>");

secondQuestion(seats);

else if (element == -1 && input == 2)

document.writeln("The Economy Class is already fully booked<br/>");

secondQuestion(seats);

else

boarding Pass(input);

else

window.status="Byebye!";

System.exit(0);

}}}
function linear Search(the Array)

if (input == 1)

for (var n=0; n<6 ; n++)

if (theArray [n] == 0) return n;

else if (input == 2)

for (var n=6; n<11 ; n++)

if (the Array [n] == 0)

return n;

return -1;

function boarding Pass(the Input)

if (input ==1)

document.writeln("----------BOARDING PASS----------<br/>");

document.writeln("You are allocated in the First Class<br/>");

document.writeln("Your seat number is "+ element+"<br/>");

document.writeln("-----------------------------------------<br/>");
seats[element]= 1;

firstCount++;

else if (input ==2)

document.writeln("----------BOARDING PASS----------<br/>");

document.writeln("You are allocated in the EconomyClass<br/>");

document.writeln("Your seat number is"+ element +"<br/>");

document.writeln("-----------------------------------------<br/>");

seats[element]= 1;

economyCount++;

functionsecondQuestion(theArray)

if (input == 1)

for (var n=6; n<11 ;n++)

if (theArray [n] == 0)

second Input = window.prompt("Do you want to move to Economy Class?(If YES,


please press 1. If NO, please press 2)","0");
if ( second Input == 1)

input = 2;

element=linear Search(seats);

document.writeln("You have been allocated to Economy Class<br/>");

boardingPass(input);

break;

else if (secondInput == 2)

document.writeln("Next flight leaves in 3 hours<br/>"); break;

else if (input == 2)

for (var n=0; n<6 ;n++)

if (theArray [n] == 0)

secondInput = window.prompt("Do you want to move to First Class? (If YES,


please press 1. If NO, please press 2)","0");
for (var n=0; n<6 ;n++)

if (theArray [n] == 0)

secondInput = window.prompt("Do you want to move to First Class? (If YES,


please press 1.If NO, please press 2)","0");

boarding Pass(input); break;

else if (secondInput == 2)

document.writeln("Next flight leaves in 3 hours<br/>");

break;

</script>

</head>

<body onload ="startArray()"></body>

</html>
20. Write a JSP program to calculate income tax, login and data capture.

Income Tax:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Calculate Interest JSP</title>

</head>

String fname = request.getParameter("fname");

String lname = request.getParameter("lname");

String gender = request.getParameter("gender");

String profession = request.getParameter("profession");

String prefix = " ";

if (gender.equals("Male"))

prefix = "Mr.";

else if (gender.equals("Female"))

{
prefix = "Ms.";

<FONT COLOR = "Blue">Hello <%=prefix %><%=fname%>;<%=lname%>


who works in a <%=profession %></FONT>

String sincome = request.getParameter("income");

float income = Float.parseFloat(sincome);

out.println("<BR>Your Annual Income is <FONT COLOR = Blue> " +income +


"</FONT>");

float tax;

float diff;

if(income <= 100000)

out.println("<BR>You are below the Tax Bracket!!");

else if(income >100000 && income <= 200000)

out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.2,00000");

out.println("<BR><B><U> Tax Rule: </U></B>10% of income above Rs.1


Lakh");

diff = income - 100000;

tax = (float)0.1*diff;

out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");

else if(income >200000 && income <= 300000)


{

out.println("<BR>Your Tax Bracket is between between Rs.1,00000 to


Rs.3,00000");

out.println("<BR><B><U>Tax Rule: </U></B> 10% of income upto Rs.1 Lakh


and 20% of rest of income");

diff = income - 200000;

tax = (float)0.2*diff + (float)0.1*100000;

out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");

else if(income >100000 && income <= 400000)

out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.4,00000");

out.println("<BR><B><U>Tax Rule: </U></B>10% of income upto Rs.1 Lakh


20% of income upto Rs.3 Lakh and 30% of rest of income");

diff = income - 300000;

tax = (float)0.3*diff + (float)0.2*200000 + (float)0.1*100000;

out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax);

else if(income > 400000)

out.println("<BR>You fall in the tax bracket greater than Rs.4,00000");

diff = income - 400000;

tax = diff + (float)0.3*300000 + (float)0.2*200000 + (float)0.1*100000;


out.println("<BR><B><U>Tax Rule:</U></B> 10% of income upto Rs.1 Lakh
20% of income upto 3Lakh, 30% of income upto Rs.4 lakh and 100% of rest of
income");

out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");

}//end if

</body>

</html>

Datacapture.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

HashMaphm;

String uname;

String pwd;

Map.Entry entry;

boolean login = false;

hm = new HashMap();

uname = request.getParameter("username");
pwd = request.getParameter("password");

hm.put("Archie","Riverdale");

hm.put("Haddock", "Marlinspike");

hm.put("Hermione","Hogwarts");

Set s = hm.entrySet();

Iterator it = s.iterator();

while(it.hasNext())

entry = (Map.Entry) it.next();

if(uname.equals(entry.getKey()) &&pwd.equals(entry.getValue()))

login=true;

}//end while

if(login==true)

out.println("<B><FONT COLOR = Blue>");

out.println("Welcome </FONT></B>");

out.println(uname);

DateFormatdateFormat = new SimpleDateFormat("yyyy/MM/ddHH:mm:ss");

Date date = new Date();

out.println("<BR><FONT COLOR = Green>");

out.println("Today is </FONT>"+dateFormat.format(date));
<form action="CalculateInterest.jsp" method = "post">

<FONT COLOR = "Magenta"> First Name:</FONT>

<input type = "text" size = "15" name = "fname">

<br>

<FONT COLOR = "Brown">Last Name: </FONT>

<input type = "text" size = "15" name = "lname">

<br>

<FONT COLOR = "Purple">Select your Place of Work:</FONT>

<br>

<select name="profession" size="3">

<option>IT Company</option>

<option>Private Bank</option>

<option>Insurance Company</option>

</select>

<br>

<input type="radio" name="gender" value="Male"> Male<br>

<input type="radio" name="gender" value="Female" checked>Female<br>

<br>

<FONT COLOR = "Red"> Annual Income(in Rupees):</FONT>

<input type = "text" size = "15" name = "income">

<br>

<br>
<input type = "submit" value = "Calculate Tax">

</form>

else

<jsp:forward page="Login.jsp">

<jsp:param name="FailReason" value="Wrong Username or Password"/>

</jsp:forward>

</body>

</html>

Login.jsp:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Login Page</title>

</head>

<body>

<form action="dataCapture.jsp" method = "post">


User Name:

<input type = "text" size = "15" name = "username">

<br>

Password:

<input type = "password" size = "15" name = "password">

<br>

<input type = "submit" value = "Login">

</form>

</body>

</html>
Output:

You might also like