IP Lab Mannual
IP Lab Mannual
Aim
To create a web page which includes a map and display the related information when a hot spot is
clicked in the map.
Algorithm
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 use map
attribute
Step 3: Specify an area with name, shape and href set to the appropriate values
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 the user will select
Program
ImageMap.html
<HTML>
<HEAD>
<TITLE>Image Map</TITLE></HEAD>
<BODY><img src="india_map.jpg" usemap="#metroid" ismap="ismap" ><map name="metroid"
id="metroid">
<area href='TamilNadu.html' shape='circle' coords='175,495,30' title='TamilNadu'/>
<area href = "Karnataka.html" shape = "rect" coords = "100,400,150,450" title = "Karnataka" /><area
href = "AndhraPradesh.html" shape = "poly" coords = "150, 415, 175,348,265,360,190,420,190,440"
title = "Andhra Pradesh" />
<area href = "Kerala.html" shape = "poly" coords =
"108,455,150,515,115,490,148,495,110,448,155,501" title = "Kerala" /></map>
</BODY></HTML>
TamilNadu.html
<HTML>
<HEAD>
<TITLE>About Tamil Nadu</TITLE></HEAD>
<BODY>
<CENTER><H1>Tamil Nadu</H1></CENTER><HR>
<UL>
<LI>Area : 1,30,058 Sq. Kms.</LI><LI>Capital : Chennai</LI><LI>Language :
Tamil</LI><LI>Population : 6,21,10,839</LI></UL><HR>
<a href='ImageMap.html'>India Map</a></BODY></HTML>
Karnataka.html
<HTML>
<HEAD>
<TITLE>About Karnataka</TITLE></HEAD>
<BODY>
<CENTER><H1>Karnataka</H1></CENTER>
<HR>
<UL>
<LI>Area : 1,91,791 Sq. Kms</LI><LI>Capital : Bangalore</LI><LI>Language :
Kannada</LI><LI>Population : 5,27,33,958</LI></UL><HR>
<a href='ImageMap.html'>India Map</a></BODY>
</HTML>
AndhraPradesh.html
<HTML>
<HEAD>
<TITLE>About Andhra Pradesh</TITLE></HEAD>
<BODY>
<CENTER><H1>Andhra Pradesh</H1></CENTER>
<HR>
<UL>
<LI>Area : 2,75,068 Sq. Kms</LI><LI>Capital : Hyderabad</LI><LI>Language :
Telugu</LI><LI>Population : 7,57,27,541</LI></UL><HR>
<a href='ImageMap.html'>India Map</a>
</BODY>
</HTML>
Kerala.html
<HTML><HEAD><TITLE>About
Kerala</TITLE></HEAD><BODY><CENTER><
H1>Kerala</H1></CENTER><HR><UL>
<LI>Area : 38,863 Sq.
Kms.</LI><LI>Capital :
Thiruvananthapuram</LI><LI>Langu
age : Malayalam</LI><LI>Population
: 3,18,38,619</LI></UL><HR>
<a href='ImageMap.html'>India
Map</a></BODY>
</HTML>
Output
Result
Thus the creation of a web page which includes a map and display the related in-formation
when a hot spot is clicked in the map was executed successfully.
Ex.No:2 CASCADING STYLE SHEETS
Date:
Aim
To create a web page that displays college information using various style sheets
Algorithm
Step1:Create a web page with frame sets consisting two frames
Step2:In the first frame include the links
Step3:In the second frame set display the web page of the link
Step4:create a external style sheets
Step5:create a inline and internal style sheets and make it link to the external style sheets
Program
xyz.css
h3{font-family:arial;font-
size:20;color:cyan} table{border-
color:green} td{font-
size:20pt;color:magenta}
style.html
<html>
<head><h1><center>ALL STYLE
SHEETS</center></h1><title>USE of INTERNAL and
EXTERNAL STYLESHEETS </title>
<link rel="stylesheet" href="xyz.css"
type="text/css"><style type="text/css">
.vid{font-family:verdana;font-style:italic;color:red;text-align:center}
.ani{font-family:tahoma;font-style:italic;font-size:20;text-
align:center;} font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<ol style="list-style-type:lower-alpha">
<b>ARULMURUGAN GROUP OF
INSTITUTIONS</b><br><br><br><li>Arulmurugan college of engineering
<li>Arulmurugan Polytechnic
college <li> Arulmurugan arts and
science <li>Arulmurugan teacher
training </ol>
<p style="font-size:20pt;color:purple">ACE</p>
<p class="ani">Arulmurugan Group of colleges is owned by Dr.P.V.kanadasamy<br>It is
approved by AICTE(All India Council for Technical Education).
It is affliated to Anna University.<br></p>
<h2 class="vid"> Arulmurugan college of engineering </h2><br>
<font>It is an ISO certified
Institution</font><br><br>
<font>
<h2>List of Courses
offered</h2><ul>
<li>Computer Science and
Engineering</li><li>Ece</li>
<li>mech</li>
<li>eee</li>
</ul>
</font>
<h3>Results of cse students</h3>
<table width="100%" cellspacing="2" cellpadding="2"
border="5"><tr>
<th>S.NAME</t
h><th>MARKS<
/th><th>RESUL
T</th>
</tr>
<tr>
<td
align="center">Suppriya</td><t
d align="center">100</td>
<td
align="center">pass</td></
tr>
<tr>
<td
align="center">Devishree</td><t
d align="center">99</td>
<td
align="center">pass</td></
tr>
<tr>
<td
align="center">Vinayagam</td><t
d align="center">98</td>
<td
align="center">pass</td></tr></ta
ble></body></html>
Output
Result
Thus the creation of a web page that displays college information using various style sheet was
successfully executed and verified.
Ex.No:3 VALIDATE THE REGISTRATION USING JAVASCRIPT
Date:
Aim
Validate the Registration, user login, user profile and payment by credit card pages using JavaScript.
Algorithm
Step 1: Create home, login, registration, profile, catalog and order html pages.
Step 2: Create jsp pages which does all business works on the server.
Step 3: Use appropriate database to store the details of the books.
Step 4: Create tables to store login details and books de tails.
Step 5: Connect the database using odbc.jdbc driver.
Step 6: Make changes in the control settings to enable database on your local machine.
Main.html:
<html>
<frameset rows="25%,*">
<frame src="top.html" name="top" scrolling ="no" frameborder ="0">
<frameset cols="25%,75%">
<frame src="left.html" name="left" scrolling ="no" frameborder ="0">
<frame src="right.html" name="right" scrolling ="auto" frameborder ="0">
</frameset>
</frameset>
</html>
Top.html:
<html>
<body bgcolor="pink">
<br><br>
<marquee><h1 align=”center”><b><u>ONLINE BOOK STORAGE</u></b></h1></marquee>
</body>
</html>
Right.html:
<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press login if you are having id otherwise press registration.
</p></b></h2>
</body> </html>
Left.html:
<html>
<body bgcolor="pink">
<h3>
<ul>
<li><a href="login.html" target="right"><font color="black"> LOGIN</font></a></li><br><br>
<li><a href="profile.html" target="right"><font color="black"> USER PROFILE</font></a></li><br><br>
<li><a href="catalog.html" target="right"><font color="black"> BOOKS CATALOG</font></a></li><br><br>
<li><a href="scart.html" target="right"><font color="black"> SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font color="black"> PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Login.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript"> function validate()
{
var flag=1; if(document.myform.id.value==""|| document.myform.pwd.value=="")
{
alert("LoginId and Password must be filled") flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.open("catalog.html","right");
}
else
{
alert("INVALID INPUT");
//document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br> PASSWORD:<input type="password" name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</div>
</form>
</body>
</html>
Profile.html:
<html>
<body bgcolor="pink"><br><br>
<script type="text/javascript"> function validate()
{
var flag=1; if(document.myform.name.value==""||
document.myform.addr.value==""|| document.myform.phno.value==""|| document.myform.id.value==""||
document.myform.pwd.value=="")
{
alert("Enter all the details");
flag=0;
}
var str=document.myform.phno.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
if(!(str.length==10)) flag=0;
}
var str1=document.myform.id.value;
var x1=new RegExp("^[A-Z][a-zA-Z]+$","g"); if(!(str1.match(x1)))
{
flag=0;
alert("Invalid UserID");
}
var str1=document.myform.pwd.value; var x1=new RegExp("^[A-Z][a-zA-Z]+$","g"); if(!(str1.match(x1)))
{
if(flag==1)
{
flag=0;
alert("Invalid password");
}
alert("VALID INPUT");
window.self.location.href="login.html";
}
else
{
alert("INVALID INPUT");
document.myform.focus();
<br><br>
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input type="type" name="addr"><br> CONTACT
NUMBER:<input type="text" name="phno"><br> LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form></body></html>
• Books catalog:
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript"> function validate()
{
var flag=1; if(document.myform.title.value=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c"||str=="C")
{
document.myform.t1.value="C"; document.myform.t2.value=444;
}
else if(str=="jsp"||str=="JSP")
else
{
document.myform.t1.value="JSP"; document.myform.t2.value=555;
}
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" action="payment.html" target="right">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br>
</pre><br><br>
Book Title: <input type="text" name="t1" disabled> Book Cost: <input type="text" name="t2" disabled>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
<input type="submit" value="Purchase">
</form>
</body>
</html>
• Shopping cart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript"> function validate()
{
var flag=1; if(document.myform.id.value==""||
document.myform.title.value==""|| document.myform.no.value==""|| document.myform.cost.value=="")
{
flag=0;
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
else
{
alert("INVALID INPUT");
document.myform.focus();
}
</script>
<form name="myform" action="scart.html" target="right">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> TITLE :<input type="text" name="title"><br> NO.OF
BOOKS :<input type="text" name="no"><br>
COST OF BOOK :<input type="text"name="cost"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
Payment.html:
<body bgcolor="pink"><br><br><br>
<script language="javascript"> function validate()
{
var flag=1;
if(document.myform.id.value==""|| document.myform.pwd.value==""|| document.myform.amount.value==""||
document.myform.num.value=="")
{
flag=0;
}
var str=document.myform.amount.value; var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
flag=0;
}
var str1=document.myform.num.value; var x1=new RegExp("\\d","g");
if(!(str.match(x1)))
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="order.html";
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input type="text" name="amount"><br>
CREDITCARDNUMBER :<input type="PASSWORD" name="num"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
</html>
• Order Conformation
<html>
Order.html:
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
OUTPUT:
Main.html
Login.html:
9
Catalog.html:
Scart.html:
Payment.html:
Order.html
Result
Thus the Validate the Registration, user login, user profile and payment by credit card pages using JavaScript.
was successfully executed and verified
Ex.No4 a) INVOKING SERVLET FROM HTML
Date:
Aim
To write a java program to invoke servlet from HTML forms.
Algorithm
Step1: Write a client side HTML program (client.html) with the following:
Insert a <form> that contains the fields such as text, password and one submit button.
Set the URL of the server as the value of form‟s action attribute.
Step2: Write a java servlet program (server.java) with the following:
Define a class server that extends the property of the class GenericServlet.
Handle the request from the client by using the method service() of GenericServlet class.
Get the parameter names from the HTML form by using the method getParameterNames().
Get the parameter values from the HTML forms by using the method getParameter().
Send the response to the client by using the method of PrintWriter class.
Step3: compile the java source code (server.java).
Step4: Run the HTML program (client.html).
Step5: Submit the form data to the server.
Program
client.html
<html>
<head>
<title>INVOKING SERVLET FROM HTML</title>
</head>
<body>
<center>
<form name = "PostParam" method = "Post" action="http://localhost:8080/Sample/servlet/serv">
<table>
<tr>
<td><B>Employee: </B></td>
<td><input type = "textbox" name="ename" size="25"
value=""></td>
</tr>
<tr>
<td><B>Phone: </B></td>
<td><input type = "textbox" name="phoneno" size="25"
value=""></td>
</tr>
<tr>
<td><b>Salary: </b></td>
<td><input type="textbox" name="salary" size="25" value=""></td>
</tr>
<tr>
<td><b>Id:</b></td>
<td><input type="textbox" name="id" size="25" value=""></td>
</tr>
</table>
<input type = "submit" value="Submit">
</form>
</center>
</body>
</html>
server.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class serv extends GenericServlet
{
public void service(ServletRequest request,ServletResponse response)throws
ServletException,IOException
{
PrintWriter out=response.getWriter();
String name=request.getParameter("ename");
String phno=request.getParameter("phoneno");
String sal=request.getParameter("salary");
String id=request.getParameter("id");
out.println("EmployeeName: "+name);
out.println("Phone No: "+phno);
out.println("id: "+id);
out.println("Salary: "+sal);
}
}
Output
Result
Thus the above program to demonstrate invoking a servlet from html was successfully executed
and verified.
Ex.No: 4b SESSION TRACKING AND HIT COUNT
Date:
Aim
To write a servlet program for Session tracking using hidden form fields and Session tracking for a
hit count.
Algorithm
Step1 : Start the program
Step2 : Import the necessary packages to access the Session class and
methods
Step3 : Set the class path for Servlet-api.jar
Step4 : Define the doGet method for providing a request and response to
the input.
Step5 : Using getCreationTime() and getLastAccessedTime() method ,
Tracking the session time.
Step6: Compile the SessionTrack.java file,then copy the class file into
classes folder in wepapps.
Step7: Open the browser and paste a URL
http://localhost:8080/SessionTrack
Step8: Stop the Program
SessionTrack.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
// ExtendHttpServlet class
public class SessionTrack extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException,IOException
{
// Create a session object if it is already not created.
HttpSession session =request.getSession(true);
// Get session creation time.
Date createTime=new Date(session.getCreationTime());
// Get last access time of this web page.
Date lastAccessTime=new Date(session.getLastAccessedTime());
String title ="Welcome Back to my website";
Integer visitCount=new Integer(0);
String visitCountKey=new String("visitCount");
String userIDKey=new String("userID");
String userID=new String("ABCD");
Output
Result
Thus the above servlet program for session tracking and hit count information was successfully
executed and verified.
Ex.No : 5 ONLINE EXAM USING SERVLET WITH THREE TIER ARCHITECTURE
Date :
Aim
To create a three tier application for displaying the student marklist.
Algorithm
Client
1. In student.html on the client side declare the contents thatlike to transfer to the
server using html form and input type tags.
2. Create a submit button and close all the included tags.
Servlet
ii) Connect with the database which has the student marklist
student.html
<html>
<head><title>Online Examination</title>
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.Seat_no.value.length==0)
{
alert("Please,fill up the Seat Number");
Form_obj.Seat_no.focus();
return false;
}
if(Form_obj.Name.value.length==0)
{
alert("Please,fill up the Name");
Form_obj.Name.focus();
return false;
}
return true;
}
</script>
</head>
<body bgcolor=lightgreen>
<center>
<h1>OnLine Examination</h1>
</center>
<form action="StudentServlet3" method="post"
name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<table>
<tr>
<td><h3>Seat Number:</h3></td>
<td><input type="text" name="Seat_no"></td>
</tr>
<tr>
<td><h3>Name:</h3></td>
<td><input type="text" name="Name" size="50"></td>
</tr>
<hr/>
<tr>
<td><b>Total Marks:10(Each question carries equal marks) </b></td>
<td></td><td></td><td></td><td><b>Time: 15 Min.</b></td>
</tr>
</table>
<hr/>
<b>1. Apache is an open source web server</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<br/>
StudentServlet3.java
package pack;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
Connection connect=null;
Statement stmt=null;
ResultSet rs=null;
public void doPost (HttpServletRequest request,HttpServletResponse response) throws
ServletException, IOException
{
//Establishing Connection to the Database
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:StudentDB1";
connect = DriverManager.getConnection(url, " ", " ");
}
catch(ClassNotFoundException e){e.printStackTrace();}
catch(SQLException e){e.printStackTrace();}
catch(Exception e){e.printStackTrace();}
SeatNum = request.getParameter("Seat_no");
Name = request.getParameter("Name");
ans1 =request.getParameter("group1");
if(ans1.equals("True"))
a1=2;
else
a1=0;
ans2 = request.getParameter("group2");
if(ans2.equals("True"))
a2=0;
else
a2=2;
ans3 = request.getParameter("group3");
if(ans3.equals("True"))
a3=0;
else
a3=2;
ans4 = request.getParameter("group4");
if(ans4.equals("True"))
a4=2;
else
a4=0;
ans5 = request.getParameter("group5");
if(ans5.equals("True"))
a5=0;
else
a5=2;
int Total=a1+a2+a3+a4+a5;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body bgcolor=pink>");
out.println("<center>");
out.println("<br><br>");
out.println("<h2>Students Database</h2>");
out.println("<table border=5>");
try
{
stmt = connect.createStatement();
String query = "SELECT * FROM StudentTable WHERE Name="+"'"+Name+"'";
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.println(" <td>"+rs.getInt(1)+"</td>");
out.println(" <td> "+rs.getString(2)+" </td>");
out.println(" <td> "+rs.getString(3)+" </td>");
out.println(" </tr>");
}
out.println("</table>");
}catch(SQLException e){}
finally
{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(connect!=null)
connect.close();
}catch(SQLException e){}
out.println("<h1>Thanks</h1>\n");
out.println("</table>");
out.println("</center>");
out.println("</body></html>");
}
}}
web.xml
JDBC-ODBC Connectivity
Result
Thus the program to create an online Examination using Servlet with three tier
architecture was executed and the output was verified successfully.
Ex.No : 6 INSTALLATION OF TOMCAT WEB SERVER
Date:
Aim
Install TOMCAT web server. Convert the static web pages of programs into dynamic web pages using
servlets (or JSP) and cookies. Hint: Users information (user id, password, credit card number) would be stored
in web.xml. Each user should have a separate Shopping Cart.
Step 1:
Installation of JDK:
Before beginning the process of installing Tomcat on your system, ensure first the
availability of JDK on your system Install it on your system if not already installed (because
any version of tomcat requires the Java 1.6 or higher versions) and then set the class path
you need to specify the
(environment variable) of JDK. To set the JAVA_HOME Variable:
location of the java run time environment to support the Tomcat else Tomcat server can not run.
it should not contain the path up to bin folder. Here, we have taken the URL path
Note:
according to our installation convention.
For Windows OS, go through the following steps:
My Computer->properties->advance->Environment
Variables->New->set the Variable name =
JAVA_HOME and variable value = C:\Program
Files\Java\jdk1.6
Now click on all the subsequent ok buttons one by one. It will set the JDK path.
Step 2:
For setting the class path variable for JDK, do like this:
First, right click on the
My Computer->properties->advance->Environment
Variables->path.
The process of installing Tomcat 6.0 begins here from now. It takes various steps for
installing and configuring the Tomcat 6.0.
For Windows OS, Tomcat comes in two forms: .zip file and .exe file (the Windows installer
file). Here we are exploring the installation process by using the .exe file. First unpack the
zipped file
and simply execute the '.exe' file.
A Welcome screen shot appears that shows the beginning of installation process. Just
click on the 'Next' button to proceed the installation process.
Steps 4:
Step 5:
A screen shot appears asking for the 'installing location'
Step 6:
A screen shot of 'Configuration Options' displays on the screen. Choose the location for the
Tomcat files as per your convenience. You can also opt the default Location
The port number will be your choice on which you want to run the tomcat server. The port
number 8080 is the default port value for tomcat server to proceed the HTTP requests. The user
can also change the 'port number' after completing the process of installation; for this, users have
to follow the following tips.
Go to the specified location as " Tomcat 6.0 \conf \server.xml ". Within the
server.xml file choose "Connector" tag and change the port number.
Now, click on the 'Next' button to further proceed the installation process.
Step 7:
This window asks for the location of the installed Java Virtual Machine. Browse the
location of the JRE folder and click on the Install button. This will install the Apache
tomcat at the specified location.
Step 8:
Step 9:
Step 10:
A window of Apache Service Manager appears with displaying the running process.
Step 11:
After completing the installation process, the Apache Tomcat Manager appears on the
toolbar panel like shown in the below picture.
Start the Tomcat Server:
1. Start the tomcat server from the bin folder of Tomcat 6.0 directory by double
clicking the "tomcat6.exe" file.
OR create a shortcut of this .exe file at your desktop.
2. Now Open web browser and type URL http://localhost:8080 in the address bar to test the
server
3. To Stop the Tomcat Server: Stop the server by pressing the "Ctrl + c" keys.
PROCEDURE:
Result
Thus the installation of TOMCAT server was installed successfully.
Ex.No:07 CONVERT THE STATIC WEB PAGES ONLINE LIBRARY INTO DYNAMIC
WEB PAGES USING SERVLETS AND COOKIES
Date:
Aim
To Redo the previous task using JSP by converting the static web pages into dynamic web
pages. Create a database with user information and books information. The books catalogue should be
dynamically loaded from the database.
Algorithm
Step 1: Create home, login, registration, profile, catalog and order html pages.
Step 2: Create jsp pages which does all business works on the server.
Step 3: Use appropriate database to store the details of the books.
Step 4: Create tables to store login details and books de tails.
Step 5: Connect the database using odbc.jdbc driver.
Step 6: Make changes in the control settings to enable database on your local machine.
Program
Shopping.html
<html>
<head>
<title> ONLINE BOOK STORES</title>
</head>
<body bgcolor="pink">
<FRAMESET ROWS="20%,*">
<FRAME NAME="A2" SCROLLING="YES" SRC="head.html">
</FRAMESET><H1 ALIGN="CENTER"><U><FONT COLOR="PURPLE">WELCOME TO
ONLINE BOOK SHOPPING<ITALIC></ITALIC>
</U></FONT></H1>
<H2> <FONT COLOR="WHITE"></FONT></H2>
<H3 ALIGN="CENTER"><A HREF="reg.html"><BR><BR>
<FONT COLOR="black"><ITALIC>REGISTRATION FORM</FONT></ITALIC><BR><BR>
<BR><BR><A HREF="user profile .html"><FONT COLOR="black"><ITALIC>USER
PROFILE</FONT></ITALIC><BR>
<BR><BR><A HREF="user login.html"><FONT COLOR="black"><ITALIC>USER
LOGIN</FONT></ITALIC><BR>
<BR><BR><A HREF="book catalog.html"><FONT COLOR="black"><ITALIC>BOOKS
CATALOG</FONT></ITALIC><BR>
<BR><BR><A HREF="confim.HTML"><FONT COLOR="black"><ITALIC>BOOKS
CART</FONT></ITALIC><BR>
<BR><BR><A HREF="payment.HTML"><FONT
COLOR="black"><ITALIC>PAYMENT</H3></FONT></ITALIC><BR>
</BODY>
</HTML>
Registration.html
<html>
<head>
<center><u><h1>Registration Form</h1></u></center>
</head>
<body>
<fieldset width=300><legend class=heading>Registration Form</legend>
<form actions="http://localhost:8080//servlet-examples//KiranUserProfile">
<pre class="reg">
First Name : <input type="text" size=30>
Last Name : <input type="text" size=30>
Age : <input type="text" size=30 onFocus="kirandisp()">
Email Id : <input type="email" size=30>
Alternate
Email Id : <input type="email" size=30>
Address :
<textarea cols=50 rows=3></textarea>
Phone : <input type="text" size=30>
Signin.html
<html>
<head><center>
<font size="6" color="Black" ><h1><u>User login. ... </u><h1></font></center>
</head>
<form method="POST" ACTION="http://localhost:8080//servlet-examples//KiranPass">
<body bgcolor="0x1ff0f2">
<pre>
Enter Name : <input type="text" name="name" size=15 > <br>
Enter Password : <input type="password" name="pwd" size=15><br>
<input type= Submit name=sbmt value="Login">
</pre>
</form></body>
</html>
KiranParameters1.java
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class KiranParameters1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String name=res.getParameter("email");
String pass=res.getParameter("password");
if(name.equals(name)&&pass.equals(pass))
{
res.setHeader("Refresh", "5; URL=KiranBooksShopping.htm");
}
else
{
res.setHeader("Refresh","5;URl=KiranUserLoginInvlid.htm");
}
}
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
out.println("</table>");
}
}
Output
Result
Thus conversion of the static web pages online library into dynamic web pages using servlets
and cookies was successfully tested and executed.
Ex.No: 08 USER LOGIN APPLICATION USING STRUT FRAME WORK
Date:
Aim
To implement a login application using JSP strut frame work.
Algorithm
Step1: start the Program
Step2: Open the Eclipse IDE and Import the necesaary struts Jar files
Step3: Modify web.xml configuration to enable struts2 framework
Step4: Writing Java class to validate the login cridentials
LoginAuthAction.java
Step5: Configuring action class in Struts configuration file
Step6: Creating jsp pages , login.jsp, welcome.jsp,index.jsp
Step7: Execute program using web browser.
Program
Main.html:
<html>
<body>
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br/><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage. Press LOGIN if you are having id otherwise press
REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"/> <input type="reset"
value="clear" />
</div>
</form>
</body>
</html>
Profile.html
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Userinfo.html
<html>
<head>
<title>User Info Entry Form</title>
</head>
<body bgcolor="white">
<form action="userinfo1.jsp" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="userName" >
</td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="text" name="sex" >
</td>
<td>(Male or female)</td>
</tr>
<tr>
<td colspan=2><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Reg.html
<html>
<body><br /><br />
<form name="myform" method="post" action="reg">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
login.java
import java.sql.*; import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp) throws
ServletException,IOException
{
PrintWriter pw=resp.getWriter(); pw.println("<html><body>");
if(id.equals(s1)&&pwd.equals(s2))
{
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>"); pw.println("<a
href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{
pw.println("<br><br>WELCOME TO "+id.toUpperCase()+"<br><br>"); pw.println("<h3><ul>");
pw.println("<li><a href=\"profile.html\"><fontcolor=\"black\"> USER
PROFILE</font></a></li><br><br>");
pw.println("<li><a href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
pw.println("<li><a href=\"order.html\"> <fontcolor=\"black\">ORDER
CONFIRMATION</font></a></li></ul><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
reg.java:
import java.sql.*; import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException,IOException
{
PrintWriter pw=resp.getWriter(); resp.setContentType("text/html"); pw.println("<html><body>");
String name=req.getParameter("name"); String addr=req.getParameter("addr"); String
phno=req.getParameter("phno"); String id1=req.getParameter("id"); String
pwd1=req.getParameter("pwd");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1522
:XE","system","tiger");
Statement stmt=con.createStatement(); String sqlstmt="select * from login"; ResultSet
rs=stmt.executeQuery(sqlstmt); int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(4))&&pwd1.equals(rs.getString(5)))
{
flag=1;
}
}
if(flag==1)
{
pw.println("<br><br>SORRY INVALID ID ALREADY EXITS
TRY AGAIN WITH NEW ID<br><br>");
pw.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}
else
{
Statement stmt1=con.createStatement(); stmt1.executeUpdate("insert into login values
('"+name+"','"+addr+"','"+phno+"','"+id1+"','"+pwd1+"')");
Catalog.java:
import java.sql.*; import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp) throws
ServletException,IOException
{
PrintWriter pw=resp.getWriter(); pw.println("<html><body>");
String title=req.getParameter("title"); try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'"; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0; while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("TITLE :"+rs.getString(1)+"<br>"); pw.println("AUTHOR
:"+rs.getString(2)+"<br>"); pw.println("VERSION :"+rs.getString(3)+"<br>");
pw.println("PUBLISHER :"+rs.getString(4)+"<br>"); pw.println("COST
:"+rs.getString(5)+"<br>"); pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID TITLE TRY AGAIN <br><br>");
profile.java:
import java.sql.*; import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class profile extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp) throws
ServletException,IOException
{
PrintWriter pw=resp.getWriter(); pw.println("<html><body>"); String id=req.getParameter("id"); try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id='"+id+"'"; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0; pw.println("<br><br><br>"); while(rs.next())
{
pw.println("<div align=\"center\">"); pw.println("NAME :"+rs.getString(1)+"<br>");
pw.println("ADDRESS :"+rs.getString(2)+"<br>");
pw.println("PHONE NO :"+rs.getString(3)+"<br>"); pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>"); pw.println("<a
href=\"profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order.java:
}
else
{
Statement stmt2=con.createStatement();
String s="select cost from book where title='"+title+"'"; ResultSet rs1=stmt2.executeQuery(s);
int flag1=0; while(rs1.next())
{
flag1=1; x=Integer.parseInt(rs1.getString(1)); amount=count*x;
pw.println("<br><br>AMOUNT:"+amount+"<br><br><br><br>"); Statement
stmt1=con.createStatement();
stmt1.executeUpdate("insert into details values('"+id+"','"+title+"','"+amount+"','"+cno+"')");
pw.println("<br>YOUR ORDER has taken<br>");
}
if(flag1==0)
{
pw.println("<br><br><br>SORRY INVALID ID TRY AGAIN ID<br><br>"); pw.println("<a
href=\"order.html\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>"); con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Web.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-
app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>struts2web</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class></filter>
<filter-mapping>
56
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
OUTPUT:
Result:
Thus the above strut Frame work program for simple login application was successfully implemented and
executed.
Ex.No: 09a) VALIDATE THE FORM USING PHP REGULAR EXPRESSION.
.
Date:
Aim
To write Validate the form using PHP regular expression.
.
Algorithm
Step1 : Start the program.
Step2 : create a JSP File for search the information from text field.
Step3 : Jsp file have showresult() function, it is triggered by onkeyup()
event.
Step4: if the input field is empty (str.length==0), the function clears the
content of the livesearch placeholder and exits the function.
Step5: If the input field is not empty, the showResult() function executes the following:
Show.jsp
<html>
<head>
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input type="text" size="30" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
</body>
</html>
Livesearch.php
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("links.xml");
$x=$xmlDoc->getElementsByTagName('link');
Link.xml
<pages>
<link>
<title>HTML a tag</title>
<url>http://www.w3schools.com/tags/tag_a.asp</url>
</link>
<link>
<title>HTML br tag</title>
<url>http://www.w3schools.com/tags/tag_br.asp</url>
</link>
<link>
<title>CSS background Property</title>
<url>
http://www.w3schools.com/cssref/css3_pr_background.asp
</url>
</link>
<link>
<title>CSS border Property</title>
<url>http://www.w3schools.com/cssref/pr_border.asp</url>
</link>
<link>
<title>JavaScript Date Object</title>
<url>http://www.w3schools.com/jsref/jsref_obj_date.asp</url>
</link>
<link>
<title>JavaScript Array Object</title>
<url>http://www.w3schools.com/jsref/jsref_obj_array.asp</url>
</link>
</pages>
Output
Result
Thus the Validate form using PHP regular expression. was successfully executed and verified.
.
Ex.No: 09(b) PHP STORES A FORM DATA INTO DATABASE.
Date:
Aim
To write a java program using the spring frame work for student application.
Algorithm
Step1: Start the Program
Step1: create the class
Step2: create the php file to provide the values
Step3: create the test class
Step4: Load the spring jar files
Step5: Run the test class
Student.html
html>
<head>
<title>Registration
Form</title>
</head>
<body>
<link href =
"registration.css"
type = "text/css" rel =
"stylesheet" />
<h2>Sign
Up</h2>
<form name =
"form1"
action="modified.php
" method = "post"
enctype =
"multipart/form-data"
>
<div class =
"container">
<div class
= "form_group">
<label>First
Name:</label>
<input
type = "text" name =
"fname" value = ""
required/>
</div>
<div class
= "form_group">
<label>Middle
Name:</label>
<input
type = "text" name =
"mname" value = ""
required />
</div>
<div class
= "form_group">
<label>Last
Name:</label>
<input type = "text"
name = "lname" value = ""
required/>
</div>
<div class
= "form_group">
<label>Password:</la
bel>
<input
type = "password"
name = "pwd" value
= "" required/>
</div>
</div>
</form>
</body>
</html>
Connection.Php
<?php
$servername="localh
ost";
$username =
"root";
$password = "";
$conn =
mysql_connect
($servername ,
$username ,
$password) or
die("unable to
connect to host");
$sql =
mysql_select_db
('test',$conn) or
die("unable to
connect todatabase");
?>
TEST.Php
<?php
while($row =
mysql_fetch_object($
result)){
?>
<tr>
<td>
<?php echo
$row->id;?>
</td>
<td>
<?php echo
$row->fname;?>
</td>
<td>
<?php echo
$row->mname;?>
</td>
<td>
<?php echo
$row->lname;?>
</td>
<td>
<?php echo
$row->pwd;?>
</td>
<td>
<?php echo
$row->cnf;?>
</td>
<td>
<?php echo
$row->mail;?>
</td>
<td>
<?php echo
$row->number;?>
</td>
<td>G
<?php echo
$row->sex;?>
</td>
<td>
<?php echo
$row->address;?>
</td>
<td>
<?php echo
$row->code;?>
</td>
<td>
<?php echo
$row->city;?>
</td>
<td>
<?php echo
$row->country;?>
</td>
<td>
<?php echo
$row->skills;?>
</td>
<td>
<?php echo
$row->attach_file;?>
</td>
<td> <a
href="listing.php?id
=
<?php echo
$row->id;?>"
onclick="return
confirm('Are You
Sure')">Delete
</a> | <a
href="index.php?id =
<?php echo
$row->id;?>"
onclick="return
confirm('Are You
Sure')">Edit
</a> </td>
<tr>
<? php } ?>
Output
Result
Thus the above php program was successfully executed and output was verified.
Ex.No:10 CUSTOMER FEEDBACK USING WEB SERVICES
Date:
Aim
To Write a web services for finding what people think by asking 500 people‟s opinion for any
consumer product
Algorithm
Step 1: Start.
Step 2: Create jsp pages which does all business works on the server.
Step 3: Use appropriate database to store the details of the books.
Step 4: Create tables to store login details and books de tails.
Step 5: Connect the database using odbc.jdbc driver.
Step 6: Make changes in the control settings to enable database on your local machine.
Program
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<!-- We are grateful to you for keeping this link in place. thank you. -->
<input type="submit" value="Submit"> ( <a
href="http://www.freecontactform.com/html_form.php">HTML Form</a> )
</td>
</tr>
</table>
</form>
Output
Result
Thus the above program for getting feedback was successfully executed and verified.