You are on page 1of 54

Ex.No.

1
Create a web page with an image map and hotspots in HTML
Date :

Aim

To create a web page which includes a map and display the related information when a
hot spot is clicked in the map

Procedure

Step 1: Create a html file with map tag

Step 2: Set the source attribute of the img tag to the location of the image and also set the
usemap attribute

Step 3: Specify an area with name, shape and hyper link reference

Step 4: Repeat step 3 as many hot spots you want to put in the map

Step 5: Create html files for each and every hot spots specifiedin the map

Program

Home.html

<html>
<title>Home - States of India!!!</title>
</head>
<body bgcolor="gold">
<h1><u><center>Republic of India</center></u></h1>
<p>
India is the Seventh Lagest country in the world by geographical area, the second most populous
country with over 1.2 billion people, and the populus democracy in the world. India is a federal
constitutional republic with a parliamentry democracy consisting of 28 states and 7 union
Terriories.
</p>
<center>
<img align="center" size="100" src="india_states_and_capitals.jpg" usemap="#india"/>
<map name="india">
<area shape="circle" coords="217,444,20" href="AndhraPradesh.html">
<area shape="circle" coords="178,645,20" href="Kerala.html">
<area shape="circle" coords="197,543,10" href="Karnataka.html">
<area shape="circle" coords="254,541,20" href="TamilNadu.html">
</map>
</center>
<h2> Features</h2>
<ul>
<li><b>Population</b> - 1,028,783,343(2001 census).
<li><b>Capital</b> - New Delhi
<li><b>Largest City</b> - Mumbai
<li><b>Currency</b> - Indian Rupee
<li><b>Time Format</b> - IST (UTC + 5:30)
<li><b>NAtion Sport</b> - Hockey
<li><b>Current PM</b> - Manmohan Singh
<li><b>Current President</b> - Prathiba Patil
</li>
</ul>
<h2>
<b>To view details of states please click on the specified area in the
map !!!</b>
</h2>
</body>
</html>

AndhraPradesh.html
<html>
<head><title>Andhra Pradesh - India</title></head>
<body bgcolor="tan">
<h1><center>Andhra Pradesh</center></h1>
<h3>A.P., is a state situated on the southeastern coast of India. It is
India's fourth largest state by area and fifth largest by population.</h3>
<h3>
<ul>
<li>Districts<i> - 23</i>
<li>Capital City<i> - Hyderabad</i>
<li>Largest City<i> - Hyderabad</i>
<li>Governor<i> - E. S. L. Narasimhan</i>
<li>Chief Minister<i> - N. Kiran Kumar Reddy</i>
<li>Population<i> - 78,323,330</i>
<li>Tourist spots<i> - Tirumala Tirupati, Charminar, Golconda Fort,
Chandragiri, Chowmahalla Place, Falaknuma Palace etc.,</i>
</ul>
<a href="Home.html">back</a>
</body>
</html>
Karnataka.html
<html>
<head><title>Karnataka - India</title></head>
<body bgcolor="wheat">
<h1><center>Karnataka</center></h1>
<h3>
<ul>
<li>Districts<i> - 30</i>
<li>Capital City<i> - Bangalore</i>
<li>Largest City<i> - Bangalore</i>
<li>Governor<i>- Hansraj Bhardwaj</i>
<li>Chief Minister<i> - D. V. Sadananda Gowda</i>
<li>Population<i> - 61,130,704</i>
<li>Tourist spots<i> - Gol Gumbaz, Mysore Palace, Keshava Temple etc.,</i>
</ul>
</h3>
<a href="Home.html">back</a>
</body>
</html>

Kerala.html
<html>
<head><title>Kerala - India</title></head>
<body bgcolor="indianred">
<h1><center>Kerala</center></h1>
<h3>
<ul>
<li>Districts<i> - 14</i>
<li>Capital City<i> - Thiruvanandapuram</i>
<li>Largest City<i> - Thiruvanandapuram</i>
<li>Governor<i> - Hansraj Bhardwaj</i>
<li>Chief Minister<i> -Oommen Chandy </i>
<li>Population<i> - 33,387,677</i>
<li>Tourist spots<i> - Edakkal Caves, Palayur, Kovalam Beach,Munnar, Kochi, Alapuzha
etc.,</i>
</ul>
</h3>
<a href="Home.html">Back</a>
</body>
</html>
TamilNadu.html
<html>
<head><title>Tamil Nadu - India</title></head>
<body bgcolor="palegreen">
<h1><center>Tamil Nadu</center></h1>
<h3>is one of the 28 states of India. Its capital and largest city is Chennai.
Tamil Nadu lies in the southernmost part of the Indian Peninsula and
is bordered by the States of puducherry, Kerala, Karnataka, Andha Pradesh.
</h3>
<h3>
<ul>
<li>Districts<i> - 32</i>
<li>Capital City<i> - Chennai</i>
<li>Largest City<i> - Chennai</i>
<li>Governor<i> - Konijeti Rosaiah</i>
<li>Chief Minister<i> - Jayalalithaa</i>
<li>Population<i> - 72,138,958</i>
<li>Tourist spots<i> - Mamallapuram, Ooty, Kodaikanal, Marina,
Madurai Meenakshi Amman Temple, Thanjavur etc.,</i>
</ul>
<a href="Home.html">back</a>
</body>
</html>

Output:
Result

Thus the web page created its covers a map and displays the related information when a
hot spot is clicked in the map.
2. Web Page Creation using CSS

Ex.No. 2 a
Inline Cascading Style Sheets
Date :

Aim

To develop a simple webpage for the college using basic HTML Tags and Inline CSS.

Procedure

Step 1:Create HTML document using any editor most preferably notepad

Step 2:Include different html tags and CSS styles using style attribute

Step 3:Include images, heading, paragraph, list of departments and table in the web page

Step 4: Save the file with an extension .html

Step 5:Execute an html file in any one of the web browsers most preferably Google Chrome

Step 6:Output will be displayed on the web browser

Program

CollegeInline.html
<html>
<head></head>
<title>Welcome to CARE</title>
<body style="background-color:pink;">
<h1 style="color:red;text-align:center;font-family:algerian;">MIET INSTITUTIONS</h1>
<img src="Lighthouse.jpg" style="width: 350px; display:block;height:100px;margin-
left:auto;margin-right:auto;align:center; ">
<h3 style="color:blue;font-style: italic;font-family: verdana;">Mission</h3>
<p style="color:maroon;font-style: italic;font-family: arial;"> To achieve academic excellence by
imparting knowledge and
skills through problem solving, practical training and design & development of innovative
projects.
</p>
<h3>Departments</h3>
<ul style="color:maroon;font-size:20px;">
<li>CSE</li>
<li>MECH</li>
<li>CIVIL</li>
<li>ECE</li>
<li>MSE</li>
</ul>
<h3>Placement<h3>
<table style="border:1px solid black;text-align:center;cell-spacing:5px;color:red;">
<tr>
<th>Year</th>
<th>No. Of Students Placed</th>
</tr>
<tr>
<td>2015</td>
<td>78</td>
</tr>
<tr>
<td>2016</td>
<td>80</td>
</tr>
<tr>
<td>2017</td>
<td>82</td>
</tr>
<tr>
<td>2018</td>
<td>85</td>
</tr>
</table>
</body>
</html>
Output

Result
Thus the web page for college has been created using HTML and Inline CSS and it has
been displayed on web browser.
Ex.No. 2 b
Embedded / Internal Cascading Style Sheets
Date :

Aim

To develop a simple webpagefor the college using basic HTML Tags and Internal CSS.

Procedure

Step 1:Create HTML document using any editor most preferably notepad

Step 2:Include different html tags and CSS styles using style tag

Step 3:Include images, heading, paragraph, list of departments and table in the web page

Step 4: Save the file with an extension .html

Step 5:Execute an html file in any one of the web browsersmost preferably Google Chrome

Step 6:Output will be displayed on the web browser

Program

College.html
<html>
<head>
<style>
body
{
background-color:pink;
}
h1
{
color:red;
text-align:center;
font-family:algerian;
}
h3
{
color:blue;
font-style: italic;
font-family: verdana;
}
ul
{
color:maroon;
font-size:20px;
}
table,th,td
{
border:1px solid black;
text-align:center;
cell-spacing:5px;
color:red;
}
img
{
width: 350px;
display:block;
height:100px;
margin-left:auto;
margin-right:auto;
align:center;
}
p
{
color:maroon;
font-style: italic;
font-family: arial;
}
</style>
</head>
<title>Welcome to CARE</title>
<body>
<h1>CARE GROUP OF INSTITUTIONS</h1>
<img src="Lighthouse.jpg">
<h3>Mission</h3>
<p> To achieve academic excellence by imparting knowledge and
skills through problem solving, practical training and design & development of innovative
projects.
</p>
<h3>Departments</h3>
<ul>
<li>CSE</li>
<li>MECH</li>
<li>CIVIL</li>
<li>ECE</li>
<li>MSE</li>
</ul>
<h3>Placement<h3>
<table>
<tr><th>Year</th>
<th>No. Of Students Placed</th>
</tr>
<tr>
<td>2015</td>
<td>78</td>
</tr>
<tr><td>2016</td>
<td>80</td>
</tr>
<tr><td>2017</td>
<td>82</td>
</tr>
<tr><td>2018</td>
<td>85</td>
</tr>
</table>
</body>
</html>

Output
Result
Thus the web page for college has been created using HTML and internal CSS and it has
been displayed on web browser.
Ex.No. 2 c
External Cascading Style Sheets
Date :

Aim

To develop a simple webpage for the college using basic HTML Tags and External CSS.

Procedure

Step 1:Create HTML document using any editor most preferably notepad

Step 2:Include different html tags and link the html file with CSS file using link tag

Step 3:Include images, heading, paragraph, list of departments and table in the web page

Step 4: Save the file with an extension .html

Step 5: Create CSS file using notepad

Step 6: Include styles for the tags specified in the html file.

Step 7: Save this file with extension .css

Step 8:Execute an html file in any one of the web browsers most preferably Google Chrome

Step 9:Output will be displayed on the web browser

Program

College.html
<html>
<link rel="stylesheet" type="text/css" href="CollegeStyle.css">
<head>
</head>
<title>Welcome to CARE</title>
<body>
<h1>CARE GROUP OF INSTITUTIONS</h1>
<img src="Lighthouse.jpg">
<h3>Mission</h3>
<p> To achieve academic excellence by imparting knowledge and
skills through problem solving, practical training and design & development of innovative
projects.
</p>
<h3>Departments</h3>
<ul>
<li>CSE</li>
<li>MECH</li>
<li>CIVIL</li>
<li>ECE</li>
<li>MSE</li>
</ul>
<h3>Placement<h3>
<table>
<tr>
<th>Year</th>
<th>No. Of Students Placed</th>
</tr>
<tr>
<td>2015</td>
<td>78</td>
</tr>
<tr>
<td>2016</td>
<td>80</td>
</tr>
<tr>
<td>2017</td>
<td>82</td>
</tr>
<tr>
<td>2018</td>
<td>85</td>
</tr>
</table>
</body>
</html>

CollegeStyle.css
body
{
background-color:lightblue;
}
h1
{
color:red;
text-align:center;
font-family:algerian;
}
h3
{
color:blue;
font-style: italic;
font-family: verdana;
}
ul
{
color:maroon;
font-size:20px;
}
table,th,td
{
border:1px solid black;
text-align:center;
cell-spacing:5px;
color:red;
}
img
{
width: 350px;
display:block;
height:100px;
margin-left:auto;
margin-right:auto;
align:center;
}
p
{
color:maroon;
font-style: italic;
font-family: arial;
}
Output

Result
Thus the web page for college has been created using HTML and External CSS and it has
been displayed on web browser.
Ex.No. 3
Client Server Application to retrieve User information from XML
Date :

Aim

To create a web page to retrieve the user information from an XML document
using User ID from the HTML form.

Procedure

Step 1: Create HTML document to get login information of the user

Step 2: Create an XML document (users.xml) which contains user id and password.

Step 3: Create another XML document (userinfo.xml) which holds certain information about the
user like name, qualification, job, address.

Step 4: Create a another HTML document to display the requested user information in the html
form.

Step 5:When user click on the submit button the user id and password will be authenticated by
using given xml file

Step 6: The user information will be fetching from another xml file

Step 7: Display the output in HTML form.

Program
Login.html
<html>
<head>
<script type="text/javascript">
function ser()
{
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("users.xml");
var id=f1.id.value;
var pass=f1.pass.value;
var x=xmldoc.getElementsByTagName("userid");
var y=xmldoc.getElementsByTagName("password");
for(i=0;i<x.length;i++)
{
if(x[i].childNodes[0].nodeValue==id)
{
if(y[i].childNodes[0].nodeValue==pass)
{
alert("successfull logged");
var ob=window.open("userinfo.html","_blank");
ob.document.f1.uid.value=x[i].childNodes[0].nodeValue;
xmldoc.load("userinfo.xml");
var x0=xmldoc.getElementsByTagName("userid");
var x1=xmldoc.getElementsByTagName("username");
var x2=xmldoc.getElementsByTagName("qualification");
var x3=xmldoc.getElementsByTagName("job");
var x4=xmldoc.getElementsByTagName("companyname");
var x5=xmldoc.getElementsByTagName("street");
var x6=xmldoc.getElementsByTagName("city");
for(var j=0;j<x0.length;j++)
{
if(x0[j].childNodes[0].nodeValue==id)
{
ob.document.f1.name.value=x1[j].childNodes[0].nodeValue;
ob.document.f1.quali.value=x2[j].childNodes[0].nodeValue;
ob.document.f1.job.value=x3[j].childNodes[0].nodeValue;
ob.document.f1.company.value=x4[j].childNodes[0].nodeValue;
ob.document.f1.address.value= x5[j].childNodes[0].nodeValue+
","+x6[j].childNodes[0].nodeValue;
}
}
}
else
alert("incorrect password");
return;
}
}
alert("incorrect userid") ;
}
</script>
</head>
<body bgcolor="pink">
<form name="f1">
<center>
<h1>Login Form</h1><br>
<B>User Id: &nbsp;&nbsp;
<input type="text" name="id"><br><br>Password:</B>
<input type ="password" name="pass"><br><br>
<input type="button" value="submit" onClick="ser()">
</center>
</form>
</body>
</html>
userinfo.html
<html>
<head>
<title>User Info</title>
</head>
<body bgcolor="lightBlue">
<center>
<h1>User Information</h1>
</center>
<form name="f1">
<pre>
User Id: <input type="text" name="uid" onblur="fun()">
User Name: <input type="text" name="name">
Qualification:<input type="text" name="quali">
Job: <input type="text" name="job">
Company: <input type="text" name="company">
Address: <textarea name="address" rows=5 cols=19></textarea>
</pre>
</form></body>
</html>
users.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<userid>1</userid>
<password>1</password>
</user>
<user>
<userid>2</userid>
<password>2</password>
</user>
<user>
<userid>3</userid>
<password>3</password>
</user>
<user>
<userid>4</userid>
<password>4</password>
</user>
<user>
<userid>5</userid>
<password>5</password>
</user>
<user>
<userid>6</userid>
<password>6</password>
</user>
<user>
<userid>7</userid>
<password>7</password>
</user>
<user>
<userid>8</userid>
<password>8</password>
</user>
<user>
<userid>9</userid>
<password>9</password>
</user>
<user>
<userid>10</userid>
<password>10</password>
</user>
</users>
userinfo.xml
<?xml version="1.0" encoding="UTF-8"?>
<userinfo>
<user>
<userid>1</userid>
<username>Abi</username>
<qualification>B.E.</qualification>
<job>Software</job>
<companyname>Infosys</companyname>
<address>
<street>Raja Street</street>
<city>Velur</city>
</address>
</user>
<user>
<userid>2</userid>
<username>Bala</username>
<qualification>M.E.</qualification>
<job>Assistant Professor</job>
<companyname>fiind</companyname>
<address>
<street>Thayanoor Village</street>
<city>Trichy</city>
</address>
</user>
<user>
<userid>3</userid>
<username>Chitra</username>
<qualification>B.E.</qualification>
<job>Programmer</job>
<companyname>CTS</companyname>
<address>
<street>Gandhi Street</street>
<city>Coimbatore</city>
</address>
</user>
<user>
<userid>4</userid>
<username>Dharsan</username>
<qualification>B.E.</qualification>
<job>Java Developer</job>
<companyname>TCS</companyname>
<address>
<street>Raja Street</street>
<city>Velur</city>
</address>
</user>
<user>
<userid>5</userid>
<username>Jamuna</username>
<qualification>M.E.</qualification>
<job>Assistant Professor</job>
<companyname>CARE Group of institutions</companyname>
<address>
<street>Devi Karumari Street</street>
<city>Chennai</city>
</address>
</user>
<user>
<userid>6</userid>
<username>Karthik</username>
<qualification>B.E.</qualification>
<job>Supervisor</job>
<companyname>Amman Institute</companyname>
<address>
<street>Amman Street</street>
<city>Kunnathur</city>
</address>
</user>
<user>
<userid>8</userid>
<username>Subikshaa</username>
<qualification>M B A</qualification>
<job>HR</job>
<companyname>Infosys</companyname>
<address>
<street>Gandhi Street</street>
<city> Namakkal</city>
</address>
</user>

</userinfo>
Output

Result

Thus the web page toget the user information from an XML document using User
ID from the HTML form has been created and executed on the web browser.
4. Java programs using socket

Ex.No. 4 a
Implementation of HTTP Request using Java Socket
Date :

Aim
To write a java socket program to demonstrate HTTP Request using java socket

Procedure

Step 1: Import all the necessary packages

Step 2: Create socket for client and server

Step 3:Accept Server response

Step 4: Open web browser, enter localhost:8080 in address bar to get the response from this
port

Step 5: Receive the response from the server port 8080

Step 6: Display the responses which is coming from server port on the console.

Program

SimpleHTTPServer.java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class SimpleHTTPServer
{
public static void main(String args[] ) throws IOException
{
ServerSocket server = new ServerSocket(8080);
System.out.println("Listening for connection on port 8080 ....");
while (true)
{
Socket clientSocket = server.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader reader = new BufferedReader(isr);
String line = reader.readLine();
while (!line.isEmpty())
{
System.out.println(line);
line = reader.readLine();
}
}
}
}

Output

D:\usha>javac SimpleHTTPServer.java

D:\usha>java SimpleHTTPServer

Listening for connection on port 8080 ....

D:\usha>java SimpleHTTPServer

Listening for connection on port 8080 ....


GET / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/68.0.3440.106 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/a
png,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Result

Thus the java socket program to demonstrate HTTP Request using java socket has been
compiled and executed.
Ex.No. 4 b
Implementation of FTP using Java Socket
Date :

Aim

To write a java socket program to transfer the file content from client to server using
FTP.

Algorithm

Step 1: Create client socket with port number and ipaddress in the client program

Step 2: Read the file name and content of the given file

Step 3: Send the specified file from client to server

Step 4: Create server socket in server program

Step 5: Receive file sent from client

Step 6: Read the content of file which is coming from client

Step 7: Display the file content as console output

Program

FTPClient.java
import java.io.*;
import java.net.*;
public class FTPClient
{
public static void main(String args[])
{
try
{
Socket client = new Socket("127.0.0.1",1234);
PrintWriter writer = new PrintWriter(client.getOutputStream());
writer.println("sample.txt");
writer.flush();
InputStreamReader stream = new InputStreamReader(client.getInputStream());
BufferedReader reader = new BufferedReader(stream);
String str = null;
while((str = reader.readLine()) != null)
{
System.out.println(str);
}
reader.close();
}
catch(Exception e)
{
System.out.println("Connection is terminated by the Server");
}
}
}

FTPServer.java
import java.io.*;
import java.net.*;
public class FTPServer
{
public static void main(String args[])
{
try
{
ServerSocket server = new ServerSocket(1234);
Socket client;
client= server.accept();
InputStreamReader stream = new InputStreamReader(client.getInputStream());
BufferedReader reader = new BufferedReader(stream);
String filename = reader.readLine();
PrintWriter writer = new PrintWriter(client.getOutputStream());
FileInputStream fileStream = new FileInputStream(new File(filename));
int ch;
while((ch = fileStream.read()) != -1)
{
writer.write(ch);
writer.flush();
}
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Input File
Output

CMD Prompt 1

D:\usha>set path=C:\Program Files\Java\jdk1.8.0_151\bin;


D:\usha>javac FTPServer.java
D:\usha>javac FTPClient.java
D:\usha>java FTPServer
D:\usha>java FTPServer

CMD Prompt 2

D:\usha>java FTPClient
Hello
Welcome
to
CARE

Result

Thus the java socket program to transfer the file content from client to server using FTP
has been compiled and executed.
Ex.No. 5
Chat application using DatagramSocket and DatagramPacket
Date :

Aim:

To create chat application using java DatagramSocket and DatagramPacket.

Algorithm

Step 1: Create client socket in the client program

Step 2:Get an IPAddress of the server

Step 3:Get the line of string to send

Step 4:Covert the given string into bytes

Step 5:Embed sending data, length of data, ipaddress and port number in DatagramPacket

Step 6:Send the packet to server

Step 7:Create server socket with client port in the server program

Step 8:Server receives packet from client

Step 9: Server send Packet to client

Step 10: Client receives packet from server.

Step 11: Step 6 continues till the client exits

Program

UDPServer.java
import java.io.*;
import java.util.*;
import java.net.*;
class UDPServer
{
public static void main(String args[]) throws Exception
{
Scanner s=new Scanner(System.in);
DatagramSocket serversock=new DatagramSocket(1234);
byte[] sdata=new byte[50];
byte[] rdata=new byte[50];
while(true)
{
DatagramPacket receivepack=new DatagramPacket(rdata,rdata.length);
serversock.receive(receivepack);
String rstr=new String(receivepack.getData());
System.out.println("From Client : "+rstr);
InetAddress ipaddress=receivepack.getAddress();
int port=receivepack.getPort();

System.out.print("Server Chat : ");


String sstr=s.nextLine();
sdata=sstr.getBytes();
DatagramPacket sendpack=new DatagramPacket(sdata,sdata.length,ipaddress,port);
serversock.send(sendpack);
}
}
}
UDPClient.java
import java.io.*;
import java.util.*;
import java.net.*;
class UDPClient
{
public static void main(String args[]) throws Exception
{
Scanner s=new Scanner(System.in);
DatagramSocket clientsock=new DatagramSocket();
InetAddress ipaddress=InetAddress.getByName("localhost");
byte[] sdata=new byte[50];
byte[] rdata=new byte[50];
while(true)
{
System.out.print("Client Chat :");
String sstr=s.nextLine();
sdata=sstr.getBytes();
DatagramPacket sendpack=new DatagramPacket(sdata,sdata.length,ipaddress,1234);
clientsock.send(sendpack);
DatagramPacket receivepack=new DatagramPacket(rdata,rdata.length);
clientsock.receive(receivepack);
String rstr=new String(receivepack.getData());
System.out.println("From Server : "+rstr);
}
}
}
Output

Result

Thus the chat application has been created using java DatagramSocket and DatagramPacket
and it has been compiled and executed.
6. Programs Using Servlet

Ex.No. 6 a
Invoke Servlet from HTML
Date :

Aim

To write a progrm toinvoke Servlet from HTML form elements.

Procedure

Step 1: Open Eclipse Indico IDE

Step 2: Select workspace

Step 3: Goto File Menu  New Dynamic Web Project (or Other  WebDynamic Web
Project)

Step 4: Enter your Project name in the given text box

Step 5: Select Target Runtime as Apache Tomcat v7.0, If it needs enter apche folder path

Select Dynamic web project module as 2.5

Step 6: Click on Next  Select Generate Web.xmldeployment descriptorcheck box at the


bottom before click on the Finish button

Step 7: Project will be displayed on project explorer Right click on the project  New 
Package  Enter package name with lowercase  Finish  New package added under SRC

Step 8: Right click on the project select  New  Other  HTML File  Enter filename
Finish

Step 9: New HTML file will be opened then include form elements in body tag

Step 10: Specify form name, method and action(Destination Server – Servlet Classname) in the
form element

Step 11: Right click on the project select  New  Other  Servlet  Enter Classname 
Next  Select required functions ie. doGet,doPost,service etc.  Finish Servlet file included
in SRC folder

Step 12: New Servlet file will be opened with skeleton class and methods

Step 13: Enter the servlet code in required function (doGet/doPost/Service) to receive input from
HTML form elements
Step 14: Save the updated code again

Step 15: Right click HTML file  Run as  Run on Server  html file will be opened on
browser  Enter your input values  Click on submit button Input values sent to servlet 
Output displayed on browser

Program

Stud.html

<html>
<head>
<style>
h2
{
text-align:center;
color:red;
}
</style>
</head>
<body bgcolor="cyan">
<form name="student" method="post" action="StudServ">
<h2>STUDENT MARK ANALYSIS </h2>
<h4>Student Name : <input type="text" name="name"><br><br>
Student Register Number : <input type="text" name="regno"><br><br>
Student OOAD Mark : <input type="text" name="ooad"><br><br>
Student TOC Mark : <input type="text" name="toc"><br><br>
Student IP Mark : <input type="text" name="ip"><br><br>
Student Maths Mark : <input type="text" name="maths"><br><br>
Student CG Mark : <input type="text" name="cg"><br><br>
<input type="submit" value="REGISTER">
</h4>
</form>
</body>
</html>

StudServ.java
package stud;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StudServ extends HttpServlet {
private static final long serialVersionUID = 1L;
public StudServ() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
int ooad=Integer.parseInt(request.getParameter("ooad"));
int toc=Integer.parseInt(request.getParameter("toc"));
int ip=Integer.parseInt(request.getParameter("ip"));
int maths=Integer.parseInt(request.getParameter("maths"));
int cg=Integer.parseInt(request.getParameter("cg"));

int total;
float average;
out.println("<center><h1>CYCLE TEST - I MARK REPORT</h1></center>");
out.println("<h3>Name :"+request.getParameter("name"));
out.println("<br>");
out.println("Regno :"+request.getParameter("regno"));
out.println("<br>");
out.println("<br>");
out.println("<br>");
out.println(" <font color='red'>Marks Secured in CT1 :</font>");
out.println("<br>");
out.println("<br>");
out.println("OOAD :"+ooad);
out.println("<br>");
out.println("TOC :"+toc);
out.println("<br>");
out.println("IP :"+ip);
out.println("<br>");
out.println("MATHS :"+maths);
out.println("<br>");
out.println("CG :"+cg);
out.println("<br>");
total=ooad+toc+ip+maths+cg;
average=(float)total/5;
out.println("Total Marks Secured : "+total);
out.println("<br>");
out.println("Percentage :"+average);
out.println("</h3>");
}
}
Output
Result

Thus the progrm to invoke Servlet from HTML form elements has been created and
exectuted.
Ex.No. 8
Lock and unlock Servlet for particular IP and Port number
Date :

Aim

To Write a program to lock and unlock servlet for particular IPAddress and Port Number

Procedure

Step 1: Right click on the project select  New  Other  Servlet  Enter Classname  Next
 Select required functions ie. doGet,doPost,service etc.  Finish

Step 2: Servlet file included in the SRC folder

Step 3: New Servlet file will be opened with skeleton class and methods

Step 4: Enter the servlet code in Service() method

Step 5: Get a key, IPAddress and port number of the current machine

Step 6: Restrict access / Lock the servelet for the specific IPAddress and port number

Step 7: Save the updated code again

Step 8: Goto project explorer  Explore our project  Explore SRC  Explore package
Right click Servlet file  Run as  Run on Server.

Step 9: Servlet Output will be displayed on the browser

Program

KeyedServerLock.java

import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class KeyedServerLock extends HttpServlet
{
private static final long serialVersionUID = 1L;
public KeyedServerLock()
{
super();
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();

String key = getInitParameter("key");


String host = request.getServerName();
int port = request.getServerPort();
if (! keyFitsServer(key, host, port))
{
out.println("Access Denied : This IP Address and PORT Number was locked !");
}
else {
out.println("valid");
}
}
private boolean keyFitsServer(String key, String host, int port)
{

if (key == null) return false;

long numericKey = 0;
try
{
numericKey = Long.parseLong(key);
}
catch (NumberFormatException e)
{
return false;
}
byte hostIP[];
try {
hostIP = InetAddress.getByName(host).getAddress();
}
catch (UnknownHostException e) {
return false;
}
long servercode = 0;
for (int i = 0; i < 4; i++) {
servercode <<= 8;
servercode |= (hostIP[i] & 255);
}
servercode <<= 32;
servercode |= port;
long accesscode = ~numericKey;
return (servercode == accesscode);
}
}

Output

Result

Thus the java program to lock and unlock servlet for particular IPAddress and Port
Number has been compiled and executed
Ex.No. 9
Session tracking using Servlet to Find Hit Count of a Page
Date :

Aim

To Write a program to lock and unlock servlet for particular IPAddress and Port Number

Procedure

Step 1: Right click on the project select  New  Other  Servlet  Enter Classname  Next
 Select required functions ie. doGet,doPost,service etc.  Finish

Step 2: Servlet file included in the SRC folder

Step 3: New Servlet file will be opened with skeleton class and methods

Step 4: Enter the servlet code in doGet( ) method

Step 5: Create HttpSession object

Step 6: Get session ID, session creation time and last access time of the session using built-in
methods

Step 7: Calculate hit count of this page by incrementing hit count for every accessing

Step 8: Save the updated code again

Step 9: Goto project explorer  Explore our project  Explore SRC  Explore package
Right click Servlet file  Run as  Run on Server.

Step 10: Hit count and session details will be displayed on the browser

Program

Cook.java

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

publicclass Cook extends HttpServlet {


privatestaticfinallongserialVersionUID = 1L;

public Cook() {
super();
}

protectedvoid doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException
{
HttpSession ses=request.getSession(true);
ServletOutputStream out=response.getOutputStream();
response.setContentType("text/html");
out.println("<html>");
out.println("<body>");
Integer val=(Integer)ses.getAttribute("sessiontest.counter");
if(val==null)
val=new Integer(1);
else
val=new Integer(val.intValue()+1);
ses.setAttribute("sessiontest.counter", val);
out.println("<h1><center> You have accessed this page for " +val +"times" +"</h1>");
out.println("Session ID : \t"+ses.getId() +"<br>");
out.println("Creation time : \t "+ses.getCreationTime() +"<br>");
out.println("Last access time : \t "+ses.getLastAccessedTime() +"<br></b>");
out.println("</body>");
out.println("</html>");
}

Result

Thus the java program to lock and unlock servlet for particular IPAddress and Port
Number has been written and executed
Ex.No. 10 a
Apache tomcat installation&
Dynamic webpage for student registration using JSP
Date :

Aim
To Install Apache Tomcat web server and create a dynamic welcome page using JSP

Procedure
Step 1: First install any one version of JDK before installing Apache Tomcat
Step 2: Install any one version of Apache Tomcat
Step 3: During installation It asks for port number, Give 8080 (Default HTML Port) or any other
port
Step 4: During installation, it request JDK path to link with apache to execute JSP and Servlet
coding. Finally click on the finish button.
Step 5: Click on the start menu to open Apache Tomcat then welcome page will be opened
which indicates the Apache software has been installed successfully
Step 6: Write the JSP code and HTML design code in a separate notepad
Step 7: Save the JSP file in ROOT folder of Apache with an extension .jsp and then save HTML
file with the extension of .html
Step 8: Before execution of JSP file, start Apache Tomcat by click on the START button
Enter “http:\\localhost:8080\\File Path” in the Address bar of Browser to execute
Step 9: The output will be displayed on the same browser

Program
firstjsp.html
<html>
<body>
<h1>Welcome To JSP</h1>
<form name="frm" method="post" action="hellousha.jsp">
<input type="text" name="t1" value="">
<br>
<input type="submit" value="Click Here">
</form>
</body>
</html>

hellousha.jsp
<html>
<body>
<p><font size="6"> Hello Welcome
<%=request.getParameter("t1") %>
</font></p>
</body>
</html>
Apache Tomcat Installation
Output for Dynamic Welcome Page

firstjsp.html Save this file in Root folder which is present in WEBAPPS of


Apache Software Foundation folder

Path : http://localhost:8080/firstjsp.html

hellousha.jsp Save the file in Root folder which is present in WEBAPPS of


Apache Software Foundation folder

Path :http://localhost:8080/hellousha.jsp

Result

Thus the Apache Tomcat web server has been installed, the dynamic welcome page has been
created using JSP and the page output has been displayed on the browser
Ex.No. 10 a
Dynamic webpage for student registration using JSP
Date :

Aim

To create a dynamic webpage for student registration using HTML forms and JSP

Procedure

Step 1: Open Eclipse Indico IDE

Step 2: Select workspace

Step 3: Goto File Menu  New Dynamic Web Project (or Other  WebDynamic Web
Project)

Step 4: Enter your Project name in the given text box

Step 5: Select Target Runtime as Apache Tomcat v7.0, If it needs enter apche folder path

Select Dynamic web project module as 2.5

Step 6: Click on Next  Select Webdescriptor.xml check box at the bottom before click on the
Finish button

Step 7: Project will be displayed on project explorer Right click on the project  New 
Package  Enter package name with lowercase  Finish  New package added under SRC

Step 8: Right click on the project select  New  Other  HTML File  Enter filename
Finish

Step 9: New HTML file will be opened then include form elements in body tag

Step 10: Specify form name, method and action(Destination Server – Filename.jsp file) in the
form element

Step 11: Right click on the project select  New  Other WebJSP File Enter File
name Next  Finish JSP file included in Web Content folder

Step 12: New JSP file will be opened with skeleton

Step 13: Enter the JSP code to receive input from HTML form elements

Step 14: Save the updated code again


Step 15: Right click HTML file  Run as  Run on Server  html file will be opened on
browser  Enter your input values  Click on submit button Input values sent to JSP
Output displayed on the browser

Program

StudentRegistration.html

<html>
<head>
<style>
h2
{
text-align:center;
color:red;
}

</style>
</head>
<body bgcolor="cyan">
<form name="student" method="post" action="StudentReg.jsp">
<h2>ANNA UNIVERSITY, CHENNAI COUNSELING </h2>
<h2>ONLINE REGISTRATION FORM </h2>
<h4>Student Name : <input type="text" name="name"><br><br>
Father Name : <input type="text" name="fname"><br><br>
Date of Birth : <input type="text" name="dob"><br><br>
Age : <input type="text" name="age"><br><br>
City : <input type="text" name="city"><br><br>
State : <input type="text" name="state"><br><br>
Address : <br><textarea rows="4" cols="50" name="address"></textarea><br><br>
Gender : <input type="radio" name="gender" value="male"> Male<input type="radio"
name="gender" value="female">Female<br><br>
Select the College:
<select name="college">
<option value="CARE">CARE Group of Institutions</option>
<option value="MAMCET">M.A.M.C.E.T</option>
<option value="SACET">S.A.C.E.T</option>
<option value="JJCE">JJ College of Engineering</option>
</select><br><br>
Select the Department :
<select name="dept">
<option value="CSE">CSE</option>
<option value="MECH">MECH</option>
<option value="ECE">ECE</option>
<option value="CIVIL">CIVIL</option>
</select><br><br>
<input type="submit" value="REGISTER">
</h4>
</form>
</body>
</html>

StudentReg.jsp

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


pageEncoding="ISO-8859-1"%>
<html>
<head>
<style>
h1
{
text-align:center;
color:red;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>ANNA UNIVERSITY, CHENNAI COUNSELING </h1>
<h1>ONLINE REGISTRATION DETAILS </h1>
<h3>
Name : <%=request.getParameter("name") %><br><br>
Father Name : <%=request.getParameter("fname") %><br><br>
Date of Birth : <%=request.getParameter("dob") %><br><br>
Age : <%=request.getParameter("age") %><br><br>
City : <%=request.getParameter("city") %><br><br>
State : <%=request.getParameter("state") %><br><br>
Address : <%=request.getParameter("address") %><br><br>
Gender : <%=request.getParameter("gender") %><br><br>
College : <%=request.getParameter("college") %><br><br>
Department : <%=request.getParameter("dept") %><br><br>
</h3>
</body>
</html>
OUTPUT

Result

Thus the dynamic webpage for student registration using HTML forms and JSP has
been created and displayed on browser.
Ex.No. 10 b
Dynamic webpage using JSP cookies
Date :

Aim

To create a dynamic webpage to send cookie information from HTML form elemetns
toJSP

Procedure

Step 1: Open Eclipse Indico IDE

Step 2: Select workspace

Step 3: Goto File Menu  New Dynamic Web Project (or Other  WebDynamic Web
Project)

Step 4: Enter your Project name in the given text box

Step 5: Select Target Runtime as Apache Tomcat v7.0, If it needs enter apche folder path

Select Dynamic web project module as 2.5

Step 6: Click on Next  Select Webdescriptor.xml check box at the bottom before click on the
Finish button

Step 7: Project will be displayed on project explorer Right click on the project  New 
Package  Enter package name with lowercase  Finish  New package added under SRC

Step 8: Right click on the project select  New  Other  HTML File  Enter filename
Finish

Step 9: New HTML file will be opened then include form elements in body tag

Step 10: Specify form name, method and action(Destination Server – Filename.jsp file) in the
form element

Step 11: Right click on the project select  New  Other WebJSP File Enter File
name Next  Finish JSP file included in Web Content folder

Step 12: New JSP file will be opened with skeleton

Step 13: Enter the JSP code to receive cookie information(user history) from HTML form
elements

Step 14: Save the updated code again


Step 15: Right click HTML file  Run as  Run on Server  html file will be opened on
browser  Enter your input values  Click on submit button Input values sent to JSPUser
History / Cookie information displayed on the browser

Program

CookieSample.html

<html>
<body>
<center><h1>LOGIN FORM</h1></center>
<form action="CookieServer.jsp" method="GET">
Username: <input type="text" name="username">
<br><br>
Email: <input type="text" name="email" />
<br><br>
<input type="submit" value="Submit" />
</form>
</body>
</html>

CookieServer.jsp

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


pageEncoding="ISO-8859-1"%>
<html>
<body>
<%

Cookie username = new Cookie("username",request.getParameter("username"));


Cookie email = new Cookie("email",request.getParameter("email"));

username.setMaxAge(60*60*10);
email.setMaxAge(60*60*10);
response.addCookie( username );
response.addCookie( email );
%>
<center><h1>COOKIES USING JSP</h1></center><br><br>
User Name : <%=request.getParameter("username") %><br><br>
Email : <%=request.getParameter("email") %>

</body>
</html>
Output

Result

Thus the dynamic webpage to send cookie information from HTML form elemetns to
JSP has been created and executed on browser

You might also like