You are on page 1of 87

EX NO : 01 IMAGE MAPPING

AIM:
To create a web page using HTML to embed a map, to fix the hotspots in that map and
show all the related information when the hot spots are clicked.

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 would select.

1
PROGRAM:
//india.html
<html> <head>
<title>Image Mapping</title>
</head>
<body> <center>
<img src="india.gif" usemap="#india" alt="india map">
<map name="india">
<area name="tamilnadu" shape="circle" coords="357,989,30" href="tamilnadu.html">
</map> </center>
</body> </html>

//tamilnadu.html
<html><head>
<title>Image Mapping</title></head>
<body><center>
<img src="tamilnadu.gif" usemap="#tamilnadu" alt="TamilNadu">
<map name="TamilNadu">
<area name="vellore" shape="circle" coords="363,60,30" href="vellore.html">
<area name="kanchi" shape="circle" coords="446,102,30" href="kanchi.html">
<area name="coimbatore" shape="circle" coords="224,228,30" href="coimbatore.html">
<area name="chennai" shape="circle" coords="471,47,30" href="chennai.html">
<area name="madurai" shape="circle" coords="290,293,30" href="madurai.html">
</map><br><br>
<p>TamilNadu is the 11th largest state in India and Chennai is the capital.Literacy rate is
80.33% and Tamil is the official language. </p>
<a href="india.html">Home Page</a>
</center> </body> </html>

//vellore.html
<HTML>
<HEAD><TITLE>About Vellore</TITLE></HEAD>
<BODY>
<CENTER> <H1>Vellore</H1> </CENTER>
<img src="vellore.gif">
<p><font size="5pt" color="green">
Vellore, the fort-city of TamilNadu is located on the banks of Palar River.
</font></p><br><br>
<a href="tamilnadu.html">Click here to TamilNadu districts page</a>
</BODY></HTML>

//chennai.html
<HTML>
<HEAD> <TITLE>About Chennai</TITLE></HEAD>
<BODY>

2
<CENTER> <H1>Chennai</H1> </CENTER>
<img src="chennai.gif">
<pre><font type="cambria" color="red" size="15pt">
Chennai is the largest and capital city of TamilNadu.
</font></pre><br>
<a href="tamilnadu.html">Click here to TamilNadu districts page</a>
</BODY></HTML>

//coimbatore.html
<HTML>
<HEAD>
<TITLE>About Coimbatore</TITLE></HEAD>
<BODY><CENTER><H1>Coimbatore</H1></CENTER>
<img src="Coimbatore.gif">
<p><font size="5pt" color="black">
Coimbatore is the great industrial place of TamilNadu.
</font></p>
<a href="tamilnadu.html">Click here to TamilNadu districts page</a>
</BODY></HTML>

3
OUTPUT :

RESULT:
Thus the html program for creating hotspots for various districts in TamilNadu was written
and executed successfully.

4
EX NO : 02 CASCADING STYLE SHEETS (CSS)

AIM:
To write a html program to create college website with various css styles like inline,
embedded and external styles.

ALGORITHM:
1. Create a html file using frames.
2. Inside the head tag define the style element to embedded sytle and Link element to call the
external file.
3. Close the head tag.
4. Inside the body tag define the required heading h1 to h6 paragraph and various elements to create
website
5. Close the body tag and all opened tags.
6. Create a external css file and call that page to several html files.
7. Execute the program.

5
Home.html:
<html>
<head>
<title>Home</title>
</head>
<frameset rows="30%,*">
<frame src="frame1.html">
<frameset cols="30%,*">
<frame src="frame2.html" name="f2">
<frame src="frame3.html" name="f3">
</frameset>
</html>

Frame1.html:
<html>
<head>
<title>Frame1</title>
</head>
<body bgcolor="green">
<h1 style="color.yellow";font-size:25pt>
<font color=yellow>
<center>KINGSTON</center>
</font>
</h1>
<h2 style="color.cyan;font-size:15pt">
<font color=white>
<center>Affliated to AnnaUniversity</center>
</font>
</h2>
</body>
</html>
Frame2.html:
<html>
<head>
<title>Frame2</title>
<style type="text/css">
h1
{
font-size:30pt;
color:pink;
}
</style>
</head>
<body bgcolor="yellow">

6
<a href="Introduction.html" target=f3>Introduction</a><br/>
<a href="Department.html" target=f3>Department</a><br/>
<a href="Feedback.html" target=f3>FeedBack</a><br/>
<a href="Gallery.html" target=f3>Gallery</a><br/>
</body>
</html>

Frame3.html:
<html>
<head>
<title>Frame3</title>
<style type="text/css">
h1
{
font-size:25pt;
color:blue;
}
</style>
</head>
<body bgcolor="tan">
<h1><center> You are in Home Page</center></h1>
</body>
</html>

Introduction.html:
<html>
<head>
<title>Introduction</title>
</head>
<body bgcolor="black">
<font color=red>
<p> Welcome to Kingston </p>
</font>
</body>
</html>

Department.html:
<html>
<head>
<title>Departments</title>
</head>
<body bgcolor="pink">

7
<h1>Departments</h1>
<hr>
<ul>
<li><a href="Cse.html" target=f3>Cse</a><br\></li>
<li><a href="It.html" target=f3>It</a><br\></li>
</ul>
</body>
</html>

Cse.html:
<html>
<head>
<title>Cse</title>
<link rel="stylesheet" type="text/css" href="D:\sdg\ab\css1.css">
</head>
<body bgcolor="cyan">
<center><h1>Computer Science</h1></center>
<hr>
<ol>
<li>No of students:200</li>
<li>No of Staffs:20</li>
</ol>
</body>
</html>

It.html:
<html>
<head>
<title>Cse</title>
<link rel="stylesheet" type="text/css" href="D:\sdg\ab\css1.css">
</head>
<body bgcolor="magenta">
<center><h1>Information technology</h1></center>
<hr>
<ol>
<li>No of students:150</li>
<li>No of Staffs:10</li>
</ol>
</body>
</html>

Feedback.html:
<html>
<head>

8
<title>Cse</title>
</head>
<body bgcolor="black">
<p>
<font color=green>
To give your feedback, mail us to kingston@yahoo.in
</font>
</p>
</body>
</html>

Gallery.html:
<html>
<head>
<title>Gallery</title>
</head>
<body>
<div align="center">
<table border=2>
<tr>
<th>Sunset</th>
<th>Winter</th>
</tr>
<tr>
<td>
<img src="C:\Documents and Settings\All Users\Documents\My Pictures\Sample
Pictures\Sunset.jpg">
</td>
<td>
<img src="C:\Documents and Settings\All Users\Documents\My Pictures\Sample
Pictures\Winter.jpg">
</td>
</tr>
</table>
</div>
</body>
</html>

Css1.css:
h1
{
font-family:times new roman;
color:green;
font-size:20pt

9
}
h2
{
font-family:arial;
color:blue;
}

OUTPUT :

10
RESULT:
Thus the various css styles like inline, external and embedded were implemented with html
web applications.

11
Ex No: 3 JAVA SCRIPT FORM VALIDATING

AIM:
To write a html program to validate the web form controls using DHTML.
embedded and external styles.

ALGORITHM:
1. Create a html file for new sign up registration form.
2. Inside the head tag define the script to validate the html form and display the output.
3. Close the head tag.
4. Inside the body tag to create a registration form using web form controls.
5. Close the body tag and all opened tags.
6. In button submit call the function to validate the controls.
7. Execute the program.

12
PROGRAM :

<html>
<head>
<title>Student Registration Form</title>
<script type="text/javascript">
<!--
function validate()
{
if(document.signup.fname.value=="")
{
alert("Please Enter First Name!");
return false;
}
if(document.signup.lname.value=="")
{
alert("Please Enter Last Name!");
return false;
}
if(document.signup.uname.value=="")
{
alert("Please Enter User Name!");
return false;
}
if(document.signup.pword1.value=="")
{
alert("Please Enter Password!");
return false;
}
if(document.signup.pword1.value.length<6)
{
alert("Please Enter Minimum 6 Characters!");
return false;
}
if(document.signup.pword2.value=="")
{
alert("Please Enter password again!");
return false;}
if(document.signup.pword2.value!=document.signup.pword1.value)
{
alert("Password is mismatch.Re-enter password!");
return false;
}
alert("Details entered successfully");

13
display();
}
function display()
{
document.writeln('<h2>'+"Details Entered..."+'</h2>');
document.writeln('<br/>'+"First Name:"+document.signup.fname.value);
document.writeln('<br/><font color="#0066FF">'+"Last
Name:"+'</font>'+document.signup.lname.value);
document.writeln('<br/><font color="#0066FF">'+"User
Name:"+'</font>'+document.signup.uname.value);
document.writeln('<br/><font
color="#0066FF">'+"Country:"+'</font>'+document.signup.country.value);
document.writeln('<br/><font color="#0066FF">'+"Phone
No:"+'</font>'+document.signup.phno.value);
}
-->
</script>
</head>
<body align="center" bgcolor="grey">
<table width="100%" height="100%">
<td colspan="2" width="15%">
</td>
<td colspan="1" bgcolor="#FFFFFF" width="70%" height="100%">
<h1 align="center"><font color="#0066F"> Kingston -MAIL</font></h1>
<h2 align="center"><font color="#0066FF">New User Signup Form</font></h2>
<form name="signup" onsubmit="return validate()">
<font face="Verdana,Arial,Helvetica,Sans-serif" color="#660000" size="2">
<p>*First Name:<input type="text" name="fname" size="20">
*Last Name:<input typte="text" name="lname" size="20"></p>
<p >*User Name:<input type="text" name="uname" size="20">@mnmmail.com</p>
<p >*Password:<input type="password" name="pword1">(min 6 characters)</p>
<p>Confirm Password:<input type="password" name="pword2"></p>
<p>Gender:
<input type="radio" name="gen" value="male">Male
<input type="radio" name="gen" value="female">Female
</p>
<p>Country:
<select name="country">
<option selected>Select Country</option>
<option name="country" value="india">India</option>
<option name="country" value="russia">Russia</option>
<option name="country" value="france">France</option>
<option name="country" value="italy">Italy</option>
</select>

14
</p>
<p>
<p>Language Known:<br/>
<input type="checkbox" name="lang" value="tamil">Tamil<br/>
<input type="checkbox" name="lang" value="engish">English<br/>
<input type="checkbox" name="lang" value="hindi">Hindi<br/>
<input type="checkbox" name="lang" value="malayalam">Malayalam<br/>
</p>
<p >Phone No:<input type="text" name="phno" size="20"></p>
<p align="center"><input type="checkbox" name="agree" value="agree">I agree the terms and
conditions</p>
<p align="center"><input type="submit" value="submit"><input type="Reset"
value="Reset"></p>
</font>
</form>
</td>
<td colspan="2" width="15%">
</td>
</table>
</body>
</html>

15
OUTPUT:

16
RESULT:

17
Thus the program Client Side Scripts for Validating Web Form Controls using DHTML was
executed successfully.
EX: NO: 4a INVOKING SERVLETS FROM HTML

AIM:
To write a html program for invoking servlet from html.

ALGORITHM:
1. In html program, define the html, head and title tag. The title is Student Information
and close the title and head tag.
2. Define the body tag to create form and table simultaneously.
3. The table consists of following information Roll no, Student name, Address, Phone no
and total marks.
4. In the servlet program, import the summary package and create an own servlet class
extends with generic servlet.
5. In the service method, define request and response.
6. Create an object for printwriter and getwriter() value.
7. The enumeration object gets the servlet request parameters.
8. Create objects for string method and it is displayed. Similarly another object value
received and displayed.

18
PROGRAM:

FILE NAME: invokeServlet.html

<html> <head>
<title>Student's Information</title>
</head> <body>
<center>
<form name="f" action="http://localhost:8080/examples/servlet/ServletDemo">
<h3>Enter Student's Info in the following Table </h3>
<table border="1">
<tr>
<td>Roll_no</td>
<td><input type="text" name="Roll Number" value="" size="25" /> </td>
</tr>
<tr>
<td>Students Name</td>
<td> <input type="text" name="Students Name" value="" size="25" /> </td>
</tr>
<tr>
<td>Student Address</td>
<td> <input type="text" name="Student Address" value="" size="25" /> </td>
</tr>
<tr>
<td>Phone</td>
<td> <input type="text" name="Phone" value="" size="25" /> </td>
</tr>
<tr>
<td>Total Marks</td>
<td> <input type="text" name="Total Marks" value="" size="25" /> </td>
</tr>
</table>
<input type="submit" value="Submit" />
</form>
</center>
</body>
</html>

FILE NAME: servletDemo.java


import java.util.*;
import java.io.*;
import javax.servlet.*;
public class ServletDemo extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException
,IOException
{
PrintWriter out =res.getWriter();

19
Enumeration en=req.getParameterNames();
while(en.hasMoreElements())
{
String name_received=(String)en.nextElement();
out.print("\n"+name_received+" =");
String value_received= req.getParameter(name_received);
out.println(value_received);
out.println(" ");
}
out.close();
}

20
OUTPUT:

21
RESULT:
Thus the java program to invoke servlets from HTML forms was successfully implemented.
EX: NO: 4b SESSION TRACKING FOR A HIT COUNT

AIM:
To write a java program for session tracking to display the number of visits of
a specific web page.

ALGORITHM:
1. Create HttpSession object associated with the current client.
2. Using methods for the HttpSession object, retrieve information like creation
time, last access time.
3. Declare an integer object bound to a name “visitCount”.
4. Check whether the session is new or already exists. If new, assign visitCount=0
else increment the value in visitCount by 1.
5. Display all the name/value pairs of session information.

22
PROGRAM:
//SessionTracking.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class SessionTracking extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws
ServletException, IOException
{
HttpSession session = request.getSession(true);
Date createTime = new Date(session.getCreationTime());
Date lastAccessTime = new
Date(session.getLastAccessedTime());
String title = "Welcome to my website";
Integer visitCount = new Integer(0);
String visitCountKey = new String("visitCount");
String userIDKey = new String("userID");
String userID = new String("abc");
if (session.isNew()){
title = "Welcome to my website";
session.setAttribute(userIDKey, userID);
}
else
{
visitCount = (Integer)session.getAttribute(visitCountKey);
visitCount = visitCount + 1;
userID = (String)session.getAttribute(userIDKey);
}
session.setAttribute(visitCountKey,visitCount);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
out.println(docType
+ "<html>\n" +
"<head><title>" + title +
"</title></head>\n" + "<body
bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n" +
"<h2 align=\"center\">Session
Infomation</h2>\n" + "<table border=\"1\"
align=\"center\">\n" +
"<tr bgcolor=\"#949494\">\n" +
" <th>Session
info</th><th>value</th></tr>\n" + "<tr>\n" +

23
" <td>id</td>\n" +
" <td>" + session.getId() +
"</td></tr>\n" + "<tr>\n" +
" <td>Creation
Time</td>\n" + " <td>" +
createTime +
"
</td></tr>\n"
+ "<tr>\n" +
" <td>Time of Last
Access</td>\n" + " <td>" +
lastAccessTime " </td></tr>\n" +
"<tr>\n" +
" <td>User ID</td>\n" +
" <td>" + userID +
" </td></tr>\n" +
"<tr>\n" +
" <td>Number of visits</td>\n" +
" <td>" + visitCount + "</td></tr>\n" +
"</table>\n" +
"</body></html>");
}
}

web.xml
<servlet>
<servlet-name>Session</servlet-name>
<servlet-class>SessionTracking</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Session</servlet-name>
<url-pattern>/SessionTrack</url-pattern>
</servlet-mapping>

24
OUTPUT :

RESULT:
Thus the java program for session tracking to display the number of visits of a

25
Specific web page was implemented successfully.

EX: NO: 5 THREE-TIER APPLICATION USING SERVLETS


AIM:

To write program in Java to create three-tier applications using servlets for


conducting on-line examination for displaying student mark list assuming that student
information is available in a database which has been stored in a database server.

ALGORITHM:
Step 1: Create a database in MS Access which contains students mark list information
Step 2: Create an ODBC interface to the database
Step 3: Write a servlet program to display the information in a html format
To create a Database and Table
Step 1: Open MS Access and create a database
Step 2: Design the table and populate the table
To create ODBC interface
Step 1: Click Start->Control Panel-> Administrative Tools
Step 2: Create a Microsoft Access Driver
Step 3: Add the database created using MS Access to it

To Write Servlet
Step 1: Import necessary to java packages and javax packages and classes
Step 2: Create a class that extends HttpServlet and implements ServletException and
IOException
Step 3: In the doGet() method, do the following:
i) Create a PrintWriter object
ii) Open a connection with the data source name
iii) Write a sql query and execute to get the resultset
iv) Display the resultset information in html form

PROGRAM:
//onlineexam.html
<html>
<head><title>Database Test</title></head>
<body bgcolor=white><center><h1>Online Examination</h1>
</center>
<form action="http://localhost:8080/Menaka/StudentExam" method="post">
<table><tr>
<td><b>Seat Number:</b></td>
<td><input type="text" name="seatno"></td></tr>
<tr><td><b>Name:</b></td>
<td><input type="text" name="name" size="20"></td></tr>
</table><br>
<b>1.Java is a pure object oriented language</b><br>
<input type="radio" name="quiz" value="true">True
<input type="radio" name="quiz" value="false">False<br><br>
<b>2.Javascript is a server side scripting language</b><br>
<input type="radio" name="quiz" value="true">True
<input type="radio" name="quiz" value="false">False<br><br>
<b>3.XSL was a replacement for DTD</b><br>

26
<input type="radio" name="quiz" value="true">True
<input type="radio" name="quiz" value="false">False<br><br>
<b>4.CSS is referred as "Cascading Style Sheet"</b><br>
<input type="radio" name="quiz" value="true">True
<input type="radio" name="quiz" value="false">False<br><br>
<b>5.JVM is platform independant</b><br>
<input type="radio" name="quiz" value="true">True
<input type="radio" name="quiz" value="false">False<br><br>
<input type="submit" value="Submit Answers">
<input type="reset" value="Clear Form"></center>
</form> </body></html>
//Examination.java
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Examination extends HttpServlet
{ String seatno,name,q1,q2,q3,q4,q5;
int a1,a2,a3,a4,a5;
Connection connect;Statement stmt;ResultSet rs=null;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,
IOException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:studentdb";
connect=DriverManager.getConnection(url,"","");
}
catch(ClassNotFoundException e)
{e.printStackTrace();}
catch(SQLException e)
{e.printStackTrace();}
catch(Exception e)
{e.printStackTrace();}
seatno=req.getParameter("seatno");
name=req.getParameter("name");
q1=req.getParameter("quiz");
if(q1.equals("True"))
a1=5;
else
a1=0;
q2=req.getParameter("quiz");
if(q2.equals("False"))
a2=5;
else
a2=0;
q3=req.getParameter("quiz");
if(q3.equals("False"))
a3=5;
else
a3=0;
q4=req.getParameter("quiz");
if(q4.equals("True"))
a4=5;
else
a4=0;
q5=req.getParameter("quiz");

27
if(q5.equals("False"))
a5=5;
else
a5=0;
int sum=a1+a2+a3+a4+a5;
try
{
Statement stmt=connect.createStatement();
String query="insert into student("+"seatno,name,marks"+")
values('"+seatno+"','"+name+"','"+sum+"')";
int result=stmt.executeUpdate(query);
stmt.close();
}
catch(SQLException e)
{}
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><head>Welcome</head><body bgcolor='cyan'><center><br><h2>Students
Database</h2><table border='5'>");
try
{
Statement stmt=connect.createStatement();
String query="select * from student";
rs=stmt.executeQuery(query);
out.println("<th>"+"seatno"+"</th>");
out.println("<th>"+"name"+"</th>");
out.println("<th>"+"marks"+"</th>");
while(rs.next())
{
out.println("<tr><td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("<td>"+rs.getString(3)+"</td></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("</body></html>");
}
}
//web.xml
<servlet>
<servlet-name>dbase</servlet-name>
<servlet-class>Examination</servlet-class>
</servlet>
<servlet-mapping>

28
<servlet-name>dbase</servlet-name>
<url-pattern>/StudentExam</url-pattern>
</servlet-mapping>
Output:
//Database creation

29
//Opening HTML file in browser

//Servlet access to database


RESULT:
Thus the program in Java to create three-tier applications using servlets for
conducting on-line examination for displaying student mark list was implemented
successfully.
EX: NO: 19 Implementation of JSP Struts Framework
AIM:
To write a program to implement jsp struts framework.
1.

//Servlet access to database

30
RESULT:

31
Thus the program in Java to create three-tier applications using servlets for conducting on-
line examination for displaying student mark list was implemented successfully.

EX: NO: 6a INSTALLATION OF APACHE TOMCAT WEB SERVER.

AIM:
To install and configure Apache Tomcat web server.

Procedure:

Step1: To execute tomcat setup file

32
Step2: Click the next button to install the apache tomcat

Step 3 : Execute the file and click the finish button.

33
Step 4 : Run and start the Tomcat File

34
RESULT:
The installation of apache tomcat server is executed successfully.

EX: NO: 6b DYNAMIC WEBPAGE CREATION USING SERVLETS AND COOKIES


AIM:
To write a java program for converting the static webpages of shopping cart
application into dynamic web pages using servlets and cookies.

ALGORITHM:
1. Create a html file “UserDetails.html” with fields as username, password, credit card
number and a submit button. Make form action to invoke LoginSuccess.java file if
the values in the fields are correct.
2. Create a java file that reads the values of the fields username, password, credit card
number from html file. Check the credentials and redirect the web page to
LoginSuccess.java, if field values are correct else display an error message.
3. Create a java file “LoginSuccess.java” to display the field information like username
and shopping cart information.
4. Declare servlet properties and servlet mapping appropriately in web.xml file.

PROGRAM:
//UserDetails.html
<html>
<head>
<title>User Details</title>
</head>
<body bgcolor="cyan">
<div align="center">
<br><br>
<form align="center" action="http://localhost:8080/sample/Login" method="post">
<b>Enetr UserName:<input type="text" value="" name="user" size="20">
<br><br>
<b>Enter Password:<input type="password" value="" name="pass" size="20">
<br><br>
<b>Enter Credit Card Number:<input type="text" value="" name="cardno" size="20">
<br><br><br>
<b><input type="submit" value="Login">
</form>
</div>
</body></html>

//DynamicServlet.java
import java.io.*;
import

35
javax.servlet.*;
import javax.servlet.http.*;
public class DynamicServlet extends HttpServlet
{
protected void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
Usr=req.getParameter(“user”);
String Pwd=red.getParameter(“pass”);
String
Card=req.getParameter(“cardno”);
boolean V=true;
String[]
userid=getInitParameter("username").split
(",");
String[password=getInitParameter("password").split(",");
String[] cardids=getInitParameter("cardno").split(",");
int i; for(i=0;i<userid.length;i++)
{
if(userid[i].equals(usr) && password[i].equals(pwd) && cardids[i].equals(card))
{
v=false;
Cookiec=new Cookie("newuser",usr);
c.setMaxAge(60*60);
res.addCookie(c);
res.sendRedirect("http://localhost:8080/sample/Success");
}
}
if(v==true)
{
out.println("<h4>Invalid User!Please try to login again</h4>");
out.println("<a
href='http://localhost:8080/sample/UserDetails.html'>"+"UserDetails.html"
);
}
}
}

//LoginSuccess.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginSuccess extends HttpServlet
{
protected void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException

36
{ res.setContentType("text/html"
); PrintWriter
out=res.getWriter(); Cookie[]
cookie=req.getCookies();
out.println("<html><body
bgcolor='cyan'><b><br>
<form align='center'><center>"); String username=null;
if(cookie!=null)
{
for(Cookie ck:cookie)
{
String s=ck.getName();
if(s.equals("newuser"))
username=ck.getValue(
);
}}
out.println("<h3><b>Login was successful!</h3><br><br>");
out.println("<h2>India - Shopping
Cart</h2><br><br>Welcome
"+username+"</center></form></body></html>");
out.close(); }}

//web.xml
<servlet>
<init-param>
<param-name>username</param-name>
<param-value>admin1,admin2,admin3</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>admin1,admin2,admin3</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>admin1,admin2,admin3</param-value>
</init-param>
<init-param>
<param-name>cardno</param-name>
<param-value>123,234,345</param-value>
</init-param>
<servlet-name>Tom</servlet-name>
<servlet-class>DynamicServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Tom</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>

37
<servlet>
<servlet-name>Correct</servlet-name>
<servlet-class>LoginSuccess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Correct</servlet-name>
<url-pattern>/Success</url-pattern>
</servlet-mapping>

Output:
//Open html file in browser

38
//Login credentials – Correct

//Incorrect Login credentials

39
40
RESULT:

Thus the program for converting the static web pages of shopping cart application into dynamic web pages
using servlets and cookies was implemented successfully

41
EX: NO: 7 INFORMATION RETRIEVAL FROM XML DOCUMENT

AIM:
To create and save an XML document at the server, which contains 10
users(student) information. Also to write a program, which takes user Id(based on usertype) as an
input and returns the user details by taking the user information from the XML document.

ALGORITHM:
1.Create an XML document with student details.
2.Create an HTML WITH JAVA script document to retrieve all information from the xml
document.
.3.Retrieve the xml document in any of the browser which would display the student information
based on the HTML file reference.

User Information

<?xml version="1.0"?>
<userdata>
<user1>
<jntuno>561</jntuno>
<name> chandu</name>
<phno>9989891510</phno>
<address>srikakulam</address>
</user1>
<user2>
<jntuno>540</jntuno>
<name> karteek</name>
<phno>9701443556</phno>
<address>srikakulam1</address>
</user2>
<user3>
<jntuno>525</jntuno>
<name> giri</name>
<phno>9897895301</phno>
<address>rajam</address>
</user3>
<user4>
<jntuno>526</jntuno>
<name>gopi</name>
<phno>9999789540</phno>
<address>parlakimidi</address>
</user4>
<user5>

42
<jntuno>513</jntuno>
<name> manoj</name>
<phno>9989233331</phno>
<address>hyderabad</address>
</user5>
<user6>
<jntuno>514</jntuno>
<name> balaji</name>
<phno>9999789560</phno>
<address>vizag</address>
</user6>
<user7>
<jntuno>567</jntun

<name>kiran </name>
<phno>9999178957</phno>
<address>vijayanagaram</address>
</user7>
<user8>
<jntuno>518</jntuno>
<name> sekhar</name>
<phno>789580</phno>
<address>bobili</address>
</user8>
<user9>
<jntuno>517</jntuno>
<name>chaitu</name>
<phno>789590</phno>
<address>sallur</address>
</user9>
<user10>
<jntuno>595</jntuno>
<name> sravan</name>
<phno>9000789500</phno>
<address>sklm</address>
</user10>
</userdata>

Information Retrival

<html>
<!--DOM with javascript>
<head>
<title>user profile example</title>
</head>
<body>
<script type="text/JavaScript">
var xmldoc=new
ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("data.xml");
var ele=xmldoc.documentElement;
43
var y=window.prompt("eneter user
num",1); var
node=ele.childNodes.item(y-1);
for(var i=0;i<node.childNodes.length;i++)
{
var
child=node.childNodes.item(i
); var val=child.firstChild;
document.write("<h2>"+child.nodeName+":"+val.nodeValue);
}
</script>
</body>
</html>

44
Output screens for XML document

<html> 

<body bgcolor=”pink”> 

<br><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=”/tr/login.html”>LOGIN</a> 

 href=”/tr/login.html”>REGISTRATION</a></div></pre> 

 </body></html> 

45
Result
Thus the program to get user id as input and displays the user details by taking the
user information from the XML document was executed.

46
EX:NO:8 THE BOOKS CATALOGUE SHOULD BE DYNAMICALLY LOADED FROM
DATABASE BY USING JSP

AIM:

To Create a database with user information and books information . The books catalogue
should be dynamically loaded from the database.

ALGORITHM:

1) Create your own directory under tomcat/webapps (e.g. tr1)


2) Copy the html files in tr1
3) Copy the jsp files also into tr1
4) Start tomcat give the following command
Catalina.bat run
At install‐dir/bin
5) at I.E give url as http://localhost:8081/tr1/main.html

47
Main.html:

<html>
<body bgcolor=”pink”>
<br><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=”/tr/login.html”>LOGIN</a>
href=”/tr/login.html”>REGISTRATION</a></
div></pre>

</body></html>

Login.html:

<html>

<body bgcolor=”pink”><br><br><br>
<form name="myform" method="post" action=/tr1/login.jsp">
<div align="center"><pre>
LOGIN ID : <input type="passwors"
name="pwd"></pre><br><br> PASSWORD : <input
type="password" name="pwd"></pre><br><br>

</div>
<br><br>
<div align="center">
48
<inputtype="submit"value="ok"
onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear">
</form>
</body></html>

49
Reg.html: 39

<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/reg.jsp">
<div align="center"><pre>
NAME :<input type="text"
name="name"><br> ADDRESS :<input
type="text" name="addr"><br>

CONTACT NUMBER : <input type="text"


name="phno"><br> LOGIN ID: <input
type="text" name="id"><br>

PASSWORD : <input type="password" name="pwd"></pre><br><br>

</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear">

</form>

</body>
</html>

Profile.html:

<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/profile.jsp">
<div align="center"><pre>
LOGIN ID : <input type="text" name="id"><br>
</pre><br><br>
</div>

50
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear">

</form>
</body>
</html>

Catalog.html:

<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/catalog.jsp">
<div align="center"><pre>
BOOK TITLE : <input type="text" name="title"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<inputtype="reset"value="clear"

name=”button2”>

</form>
</body>
</html>

51
Order.html:

<html>

<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/order.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD : <input type="password"
name="pwd"><br> TITLE :<input
type="text" name="title"><br>

NO. OF BOOKS : <input type="text"


name="no"><br> DATE : <input
type="text" name="date"><br>

CREDIT CARD NUMBER : <input type="password" name="cno"><br></pre><br><br>

</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset" value="clear" name=”button2”>

</form>
</body>
</html>

52
Login.jsp:

%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%

out.println(“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter(“id”);

String
pwd=request.getParameter(“pwd”);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);

Connection
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();

String sqlstmt=”select id,password from login where id=”+id+” and


password=”+pwd+””; ResultSet rs=stmt.executeQuery(sqlstmt);

int flag=0;
while(rs.nex
t())

flag=1;

if(flag==0)

out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”);


out.println(“ <a href=\”/tr1/login.html\”>press LOGIN to RETRY</a>”);
}

else
{
out.println(“VALID LOGIN ID<br><br>”);

53
out.println(“<h3><ul>”);

out.println(“<li><ahref=\”profile.html\”><fontcolor=\”black\”>USER
PROFILE</font></a></li><br><br>”);

out.println(“<li><ahref=\”catalog.html\”><fontcolor=\”black\”>BOOKS
CATALOG</font></a></li><br><br>”);
out.println(“<li><ahref=\”order.html\”><fontcolor=\”black\”>ORDER

CONFIRMATION</font></a></li><
br><br>”); out.println(“</ul>”);

out.println(“<body></html>”);
%>

54
Reg.jsp:

%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body
bgcolor=\”pink\”>”); String
name=request.getParameter(“name”);
String
addr=request.getParameter(“addr”);
String
phno=request.getParameter(“phno”);
String id=request.getParameter(“id”);

String
pwd=request.getParameter(“pwd”);
int no=Integer.parseInt(phno);

Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);

Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement();

String sqlstmt=”select id from


login”; ResultSet
rs=stmt.executeQuery(sqlstmt); int
flag=0;

while(rs.next())
{
if(id.equals(rs.getString(1)))
{
flag=1;

}
}

55
if(flag==1)
{
out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID <br><br>”);
out.println(“<a href=\”/tr1/reg.html\”>press REGISTER to RETRY</a>”);
}

else
{

Statement stmt1=con.createStatement ();


stmt1.executeUpdate (“insert into login values
(“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”); out.println (“YOU DETAILS
ARE ENTERED <br><br>”);

out.println (“<a href =\”/tr1/login.html\”>press LOGIN to login</a>”);

}
out.println (“</body></html>”);
%>

56
Profile.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter(“id”);

Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.regiserDriver(d);

Connection con=

DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();

String sqlstmt=”select * from login where


id=”+id+””; ResultSet rs=stmt.executeQuery
(sqlstmt);

int
flag=0;
while(rs.next())

{
out.println (“<div align=\”center\”>”);
out.println (“NAME
:”+rs.getString(1)+”<b
r>”); out.println
(“ADDRESS :”+rs.getString(2)+”<br>”);
out.println (“PHONE
NO :”+rs.getString(3)+”<br>”); out.println
(“</div>”);

flag=1;

if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);

57
out.println(“<a href=\”/tr1/profile.html\”>press HERE to RETRY </a>”);
}

out.println (“</body></html>”);

%>

58
Catalog.jsp:

<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
title=request.getParameter (“title”);
Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);

Connection con=

DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();

String sqlstmt=”select * from book where


title=”+title+””; ResultSet rs=stmt.executeQuery
(sqlstmt);

int
flag=0;
while(rs.nex
t())

out.println (“<div align=\”center\”>”);


out.println (“TITLE
:”+rs.getString(1)+”<br
>”); out.println
(“AUTHOR :”+rs.getString(2)+”<br>”);
out.println
(“VERSION:”+rs.getString(3)+”<br>”);
out.println (“PUBLISHER :”
+rs.getString(4)+”<br>”); out.println
(“COST :” +rs.getString(5)+”<br>”);
out.println (“</div>”);

flag=1;
}

59
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/catalog.html\”>press HERE to RETRY </a>”);
}

out.println (“</body></html>”);
%>

60
Order.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter (“id”);

String pwd=request.getParameter
(“pwd”); String
title=request.getParameter (“title”);
String count1=request.getParameter
(“no”); String
date=request.getParameter (“date”);
String cno=request.getParameter
(“cno”); int
count=Integer.parseInt(count1);

Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);

Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();

String sqlstmt=”select id, password


from login”; ResultSet
rs=stmt.executeQuery (sqlstmt);

int
flag=0,amount,x;
while(rs.next())

if(id.equals(rs.getString(1))&& pwd.equals(rs.getString(2)))
{
flag=1;

}
}
61
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);

} out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);

els
e
{ Statement stmt2=con.createStatement();
String s=”select cost from book where
title=”+title+””; ResultSet
rs1=stmt2.executeQuery(s);

int flag1=0;
{ while(rs1.nex
t())

flag1=1;
x=Integer.parseInt(rs1.getStri
ng(1)); amount=count*x;

out.println(“AMOUNT :”+amount+”<br><br><br><br
}
>”); Statement stmt1=con.createStatement ();

stmt1.executeUpdate (“insert into details


(“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”); out.println (“YOU
ORDER HAS TAKEN<br>”);

62
if(flag1==0)

out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”);

out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);


}
} out.println (“</body></html>”);%>

63
64
65
RESULT:

Thus the above program was used to successfully Create a database with user information
and books information . The books catalogue should be dynamically loaded from the database.

66
EX: NO: 9a VALIDATE THE FORM USING PHP REGULAR EXPRESSION

AIM:
To write program for validate the form using PHP regular expression.

ALGORITHM:

1.wirte the program for validating the form using in PHP with notepad. save
Your code by the extension.php.
2.PHP code must be stored on htdocs folder of Apache.
3.create a folder php-example inside the htdocs and stored all php documents.

67
PROGRAM :
Expression.php

<html>
<head><title>Sample</title></head>
<body>
<?php
print"<h3>use of preg-match function</h3>";
if(preg_match("/ggg/","I Like Programming"))
{
print "The String is Matched";
}
else
{
print "The String is not matched";
}
print"<h3>use of preg-split function</h3>";
$text="Hello:friends:how:are:you?";
print"the split is as follows...<br/>";
$chunks=preg_split("/:/",$text);
while($myval=each($chunks))
{
$val=$myval["value"];
print("<b>$val</b>");
print"<br/>";
}
?>
</body>
</html>

68
OUTPUT:

RESULT:

Thus the above program was validate successfully using PHP regular expression.

69
EX:NO:9b PHP STORES THE FORM DATA INTO DATABASE

AIM:
To write script for PHP stores the form data into database.

ALGORITHM:
1.install XAMP .
2. create the database in Mysql.
3.stores the form into database using the command.
Insert,delete,update,display.

70
PHP DOCUMENT[DBDemo.php]

<?php

$driver = 'mysql';

$database = "dbname=CODINGGROUND";

$dsn = "$driver:host=localhost;$database";

$username = 'root';

$password = 'root';

try {

$conn = new PDO($dsn, $username, $password);

echo "Database CODINGGROUND Connected\n";

}catch(PDOException $e){

echo $e->getMessage();

$sql = 'SELECT * FROM users';

$stmt = $conn->prepare($sql);

$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC))

foreach($row as $value)

echo sprintf("%s, ", $value);

echo "\n";

71
}

?>

OUTPUT:

RESULT:

Thus the above php script using ,successfully stores the form data into database.

72
EX: NO: 10 a WEB SERVICE IMPLEMENTATION FOR DYNAMIC WEBPAGE

AIM:
To implement a simple web service using Netbeans IDE application.

Procedure:
To create webservice in Java using netbeans IDE. Follow below steps to create sample
webservice in netbeans IDE.

Step 1: Create project


Open Netbeans >> Select File >> New Project >> Java Web: Web Application.

73
Click Next >> Enter Project name: 􀇮HelloWorldWebService􀇯:

Click Next >> Select Server

74
Click Finish.
Step 2: Create WebService
Right click on the project 􀇮HelloWorldWebService􀇯 >> New >> Web Service:
Enter Web service name: SayHelloService
Enter Package: com.prgguru.example

Click Finish.
Step 3: Add/Update web method
I just modified the name of webmethod from hello to sayHello:
package com.prgguru.example;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService(serviceName = "SayHelloService")
public class SayHelloService {
@WebMethod(operationName = "hello")
public String sayHello(@WebParam(name = "name") String txt)
{
return "Hello " + txt + " !";

75
}
}
Step 4: Clean and build the application
Right click on the project, select 􀇮Clean and Build􀇯.

Step 5: Deploy the application


Right click on the project, select 􀇮Deploy􀇯.

76
Step 6: Test the webservice
Right click on the web service 􀇮SayHelloService􀇯 and select 􀇮Test Web Service􀇯.

The browser would open, where the service we created can be tested.

77
//After clicking 􀇲hello􀇳
Enter the name in the textbox and hit 􀇮hello􀇯 button, we could see the response from the
server as shown below:

78
79
RESULT:
Thus the simple web service was implemented successfully using Netbeans
IDE application.

EX : 10 b WEB SERVICES - AIRLINE SERVICES

AIM :

To develop a web service application for an airline service and a travel agent and the travel
agent is searching for an airline using databases.

ALGORITHM :

1.To create a html file for travel agent to search flight information.
2.To create a webservice to provide the airline information.
3.Using JDBC can retrieve the flight information from webservice.
4.Display the available flights to travel agents
5.Execute the program.

80
PROGRAM :
NewWebService.java:
package myws;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import java.sql.*;
@WebService(serviceName = "NewWebService")
@Stateless()
public class NewWebService
{
@WebMethod(operationName = "getFlight")
public String getFlight(@WebParam(name = "src") String src, @WebParam(name = "dest")
String dest) {
Connection con;
ResultSet rs=null;
Statement stmt;

81
String str="<br>";
int no=1;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:airlinesDSN","","");
stmt=con.createStatement();
rs=stmt.executeQuery("select flightname from flight where source='"+src+"' and
destination='"+dest+"';");

while (rs.next())
str=str+(no++)+"."+rs.getString("flightname")+"<br>";
return (str);
}
catch(Exception e)
{
}
return null;
}
}

82
TravelAgentClient (Web Application)
Index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Flight Enquiry</title>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
<h1>Flight Enquiry</h1>
<form id="myform" action="flightlist.jsp" method="get">
<hr/>
<table>
<tr><td>Source</td><td><input name='src1' type='text'/></td></tr>
<tr><td>Destination</td><td><input name='dest1' type='text'/></td></tr>
</table>
<input type='submit' name='submit' value='Submit'/>
</form>
</body>
</html>

83
Flightlist.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Available Flights</title>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
<%
try
{
myws.NewWebService_Service service = new myws.NewWebService_Service();
myws.NewWebService port = service.getNewWebServicePort();
java.lang.String src = request.getParameter("src1");
java.lang.String dest = request.getParameter("dest1");
java.lang.String result = port.getFlight(src, dest);
out.println("<h1>Available Flights</h1><hr>"+result);
}
catch (Exception ex)
{
}
%>
</body>
</html>
theme.css:
h1
{
font-family:arial;

84
color:pink;
font-size:20pt;
text-align:center;
}

OUTPUT :

PROCEDURE: 1) Create your own directory under tomcat/webapps (e.g. tr1) 2) Copy the html
files in tr1 3) Copy the jsp files also into tr1 4) Start tomcat give the following command
Catalina.bat run At install‐dir/bin 5) at I.E give url as http://localhost:808

85
86
RESULT :

Thus the program for implementing web service for airline application is executed successfully.

87

You might also like