Record-cs8661-Internet Programming Lab Even Sem-2021

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 125

ANAND INSTITUTE OF HIGHER TECHNOLOGY

OLD MAHABALIPURAM ROAD, KALASALINGAM NAGAR


KAZHIPATTUR, NEAR CHENNAI-603 103.

CS8661- INTERNET PROGRAMMING LABORATORY

(2020-2021)

Name :

Reg No. :

Branch : B.E. COMPUTER SCIENCE AND ENGINEERING

Year III

Semester VI
ANAND INSTITUTE OF HIGHER TECHNOLOGY
OLD MAHABALIPURAM ROAD, KALASALINGAM NAGAR
KAZHIPATTUR, NEAR CHENNAI-603 103.

BONAFIDE CERTIFICATE
Certified that this is a Bonafide Record of work done by

Mr./Ms./Mrs. Register No: of

B.E-COMPUTER SCIENCE AND ENGINEERING in

CS8661-INTERNET PROGRAMMING LABORATORY during the Academic Year

2020- 2021 .

Staff in charge HOD

Submitted for University Examination held on ……………………..

Internal Examiner External Examiner


INDEX
S.NO DATE TITLE PAGE SIGN
NO
BASIC HTML TAGS AND SIMPLE HTML
1 20-2-2021 PROGRAMS 1

2 1-3-2021 IMAGE MAPPING USING HTML 12


CASCADING STYLE SHEETS- INLINE,
3 8-3-2021 EMBEDDED AND EXTERNAL 19

USER REGISTRATION VALIDATION USING


4 15-3-2021 JAVASCRIPT 24

INVOKE SERVLET FROM HTML


5A 22-3-2021 35

INVOKE SERVLET FROM APPLET


5B 30-3-2021 38

ONLINE EXAM USING SERVLETS


6 8-4-2021 41
INSTALL TOMCAT WEB SERVER(static web
7 16-4-2021 pages into dynamic web pages) 46

REDO THE PREVIOUS TASK USING JSP


8 23-4-2021 60

CREATE AN XML DOCUMENT:TAKE THE


9
30-4-2021 INFORMATION FROM THE XML 71
DOCUMENT
DATA VALIDATION USING PHP
10A 10-5-2021 74

STORES DATA USING PHP


10B 10-5-2021 75

WEB SERVICE FOR OPINION FINDING


11 19-5-2021 78

ADDITIONAL PROGRAMS
 FORM VALIDATION USING JAVA SCRIPT
 SERVLET PROGRAM
 JSP WITH SESSION AND COOKIES
12 27-5-2021 85-125
 DATABASE ACCESS
 WEB APP USING PHP
 HIDDEN FORM FIELDS(SESSION TRACKING)
Page No:1

Ex.No:1 BASIC HTML TAGS AND SIMPLE HTML PROGRAMS


Date:

AIM:
To study about the basic HTML tags and write simple HTML programs.

ALGORITHM:
1. Start the program.
2. Study about the various HTML tags and its uses.
3. Use the HTML tags to create web application.
4. Create web pages using frames tag.
5. Add the different styles to the web pages.
6. Stop the program
DESCRIPTION:
Basic tags
1. <HTML> and </HTML>

Purpose: Indicates the beginning and the end of an HTML document

2. <HEAD> and </HEAD>

Purpose: Indicates the beginning and the end of an Header section of a document

3. <TITLE> and </TITLE>

Purpose: Specifies the text that should appear on the title bar of a browser window

4. <BODY> and </BODY>

Purpose: Indicates the beginning and the end of the document‟s content

5. <H1>…<H6> and </H1>…</H6>

Purpose: Headings are defined within these tags

<H1> defines the largest heading

<H6> defines the smallest heading


Page No:2

6. <P> and </P>

Purpose: Indicates the beginning and end of a paragraph in a HTML document

7. <BR>

Purpose: Inserts a line break without the need to start a new paragraph

8. <!------>

Purpose: The comment tag, which indicates the browser that the text enclosed within the tag,

should be ignored

9. <HR>

Purpose: Defines a Horizontal rule, inserts a line in the page

Text Formatting tags

10. <B> and </B>

Purpose: Displays the text enclosed with these tags in Bold

11. <I> and </I>

Purpose: Displays the text enclosed with these tags in Italics

12. <BIG> and </BIG>

Purpose: Displays the text enclosed with these tags in bigger size

13. <SMALL> and </SMALL>

Purpose: Displays the text enclosed with these tags in smaller size

14. <SUB> and </SUB>

Purpose: Displays the text enclosed with these tags as a subscript

15. <SUP> and </SUP>


Page No:3

Purpose: Displays the text enclosed with these tags as a superscript

16. <FONT> and </FONT>

Purpose: Displays the text enclosed with these tags in specified font

Anchor tag

17. <A> and </A>

Purpose: HTML uses the <A> (anchor) tag to create a link to another document.

An anchor can point to any resource on the Web

Attributes: 1. HREF - Addresses the document to link to

2. TARGET – Defines where the linked document should be displayed

Frames

18. <FRAMESET> and </FRAMESET>

Purpose: Defines how to divide the window into frames

Attributes: 1. COLS – No: of columns the window should be divided into

2. ROWS – No: of rows the window should be divided into

19. <FRAME> and </FRAME>

Purpose: Defines the page to be displayed in the frame

Attributes: 1. SRC – The web page that should be displayed in the frame

2. NAME – The name of the frame where other pages are displayed

Tables

20. <TABLE> and </TABLE>

Purpose: Defines a table


Page No:4

Attributes: 1. CELLSPACING – Spacing between two cells in table

2. CELLPADDING – Spacing between cell and its contents

3. BORDER – Defines the border of the table

21. <TR>, <TH>, <TD> and </TR>, </TH>, </TD>

Purpose: Defines a row, a heading and a cell respectively

LIST AND TABLE

Webpage.html
<html>
<head>
<title>My Web page</title>
</head>
<body bgcolor=lightyellow>
<marquee><h2 align = center>Internet Programming</h2></marquee>
<p>The topics</p>
<img src = download1.gif height = 100 width =150 align=right>
<font face = Cambria size = 4 pt color = brown>
<ol type = a>
<li>Java
<li>PHP
<li>HTML
<li>XML
</ol>
<table border = 1>
<tr><th>Webpage</th><th>Website</th></tr>
<tr><td>A document in the www</td><td>collection of webpages</td</tr>
</table>
<br>
<font color = black>
<b>Homepage</b>
<i>Startup or default page of a browser</i>
<dl><hr>
<font face = Calibri size = 8 pt color = blue>
<dt>
<small>HTML</small>
<font size =4 pt color = green>
<dd>
Used for creating webpages using markup tags
</dl>
<font face = arial size = 4 pt color = black>
Search websites
<br>
Page No:5

<a href = "http://www.google.co.in">Google</a>


<a href = "http://www.bing.com">Bing</a>
<font face = Calibri>
<br>
Other interesting pages
<br>
<a href = "Webpage2.html">Programming language</a>
<br>
<a href = "Webpage3.html">Sport cars</a>
</body>
</html>

Webpage2.html
<html>
<head>
<title>Another Page</title>
</head>
<body bgcolor = moccasin>
<a href = webpage.html><img src = download3.gif></a>
<font face = Calibri color = red>
<h2>Page of programming languages<h2>
<font color = black size = 4 pt>
<ul>
<li>Java
<li>C
<li>C++
<li>Python
<li>Ruby
<li>Perl
<li>PHP
<li>DotNet
</ul>
</body>
</html>
Page No:6

OUTPUT:
Page No:7

FRAMES AND FORMS

Frame.html
<html>
<head><title>Frames</title></head>
<frameset cols = "80% , *">
<frame src = "Form.html">
<frame src = "webpage3.html">
</frameset>
</html>

Form.html
<html>
<head><title>Forms</title></head>
<body bgcolor= aliceblue>
<h3>Welcome to Online Pizza Ordering</h3>
<marquee><i><b>ABC Pizza</b> The finest pizza in the world<i></marquee>
Visiting our page for the first time... Then
register or click <a href ="login.html">here</a> to login
<img src = "index1.gif" align = right>
<form>
<h5>Name</h5>
First Name:
<input type = "text" name = "txt1" value = "your name here"><br>
Last Name:
<input type = "text" name = "txt2" value = "your name here"><br>
Date of Birth:
<input type = "text" name = "tdt1" value = "Day" size = 2>/
<input type = "text" name = "tmt1" value = "Month" size = 2>/
<input type = "text" name = "tyt1" value = "Year" size = 4><br>
Address <br>
<textarea name = "Address" rows=5 cols=25>Enter your Address</textarea><br>
Phone:
<input type = "text" name = "pt2" value = "+91" size =2>
<input type = "text" name = "pt2" value = "" size= 10><br>
Gender
<input type = "radio" name = "ra1" value="car">Male
<input type = "radio" name = "ra2" value="bike">Female<br>
Food Preference
<input type = "checkbox" name = "chk1">Veg
<input type = "checkbox" name = "chk2">Non Veg<br>
e-Mail
<input type = "text" name = "pt3" value = ""><br>
Password
<input type = "password" name = "pt3" value = ""><br>
re-enter your password
<input type = "password" name = "pt3" value = ""><br>
<input type = "submit" value = "submit">
<input type = "reset" value = "Reset"><br>
Suggesions(if any) <br>
<textarea name = "textarea" rows=5 cols=30>Help us by improving this page</textarea>
</form>
Page No:8

<marquee>Pizza is delivered within 30 mins or you get it for free.....Happy Ordering</marquee>


Copyright ABC Pizza India
</body>
</html>

Webpage3.html
<html>
<head><title>Another Page</title></head>
<body bgcolor = beige>
<a href = webpage.html><img src = download3.gif></a>
<font face = Calibri color = red>
<h2>Page of Sport car companies<h2>
<font color = black size = 4 pt>
<ul>
<li>Bugatti
<li>Ferrari
<li>Koniegsegg
<li>Mercedes
<li>Audi
<li>Porsche
<li>Lamborghini
<li>BMW
</ul>
</body>
</html>

Login.html
<html>
<head><title>Forms</title></head>
<body bgcolor = lightcyan text = blue>
<h2>ABC Pizza</h2>
<marquee><i><b>ABC Pizza</b> The finest pizza in the world<i></marquee>
<h3>Login Page</h3>
<img src= index.gif align =right>
<form>
<font face = arial size = 4 pt color = red>
<b>e-Mail</b><input type = "text" name = "pt3" value = ""><br>
Password
<input type = "password" name = "pt3" value = ""><br>
<input type = "submit" value = "login">
</form>
<font face = calibri size = 4 pt color = blue>
<marquee>Pizza is delivered within 30 mins or you get it for free.....Happy Ordering</marquee>
Copyright ABC Pizza India
</body>
</html>
Page No:9

OUTPUT:
Page No:10

COLLEGE WEBSITE
Programs:

Main.html
<html>
<head> <title>aiht college</title> </head>
<frameset rows="15%,*">
<frame src="1.html" name=one>
<frameset cols="20%,*">
<frame src="2.html" name=two>
<frame src="3.html" name=three>
</frameset>
</frameset> </html>

1. html
<html>
<body>
<center><h1> AIHT </h1></center>
</body>
</html>

2. html
<html>
<body>
<h1> <a href="cse.html" target=three>CSE </a> </h1>
<h1> IT</h1>
<h1> ECE </h1>
</body>
</html>

3. html
<html>
<body>
Department Deatils
</body>
</html>

cse.html
<html>
<body>
staff details <br>
Mr.X <br>
Mr.Y <br>
Mrs.z
</body>
</html>
Page No:11

Output:

Result:
Thus the basic HTML tags was studied and simple HTML programs was executed
Successfully.
Page No:12

EX. NO:2 IMAGE MAPPING USING HTML


DATE:
AIM

To create a webpage with the following using html.


1) To embed an image map in a webpage.
2) To fix the hotspots.
3) To show all the related information.
4) To show all the related information when the hotspots are clicked.

ALGORITHM

1) start the program.


2) Create map.html file.
3) Set the co-ordinates for the hotspots area by using polygon, rectangle, square.
4) Create separate html file for separate hotspots.
5) Link Madhya Pradesh, Gujarat, Kashmir, etc..,
6) Finally terminate the program and embed webpage.

DESCRIPTION:
Image map:
An image-map is an image with clickable areas
usemap
 specifies an image as a client-side image-map Syntax

<img usemap="#mapname">

Value Description

#mapname A hash character ("#") plus the name or id of the <map> element to
use

<map>
Defines an image-map
Attribute:
name
 creates a relationship between the image and the map
 associated with the <img>'s usemap attribute

<area>
 Defines a clickable area inside an image-map.
 <area> element is always nested inside a <map> tag
Page No:13

Attribute:
alt
 specifies an alternate text for an area, if the image cannot be displayed.

Syntax
<area alt="text">
target
 Specifies where to open the target URL

Syntax
<area target="_blank | _self | _parent | _top | framename">

Attribute Values

Value Description

_blank Opens the linked document in a new window or tab


_self Opens the linked document in the same frame as it was clicked
_parent Opens the linked document in the parent frame
_top Opens the linked document in the full body of the window
frame name Opens the linked document in a named frame

Shape
Specifies the shape of the area
Syntax
<area shape="default|rect|circle|poly">

Value Description

default Specifies the entire region


rect Defines a rectangular region
circle Defines a circular region
poly Defines a polygonal region
coords
 Specifies the coordinates of an area in an image-map.

Syntax
<area coords="value">

Value Description

x1,y1,x2,y2 Specifies the coordinates of the left, top, right, bottom corner of the rectangle (for
shape="rect")
Page No:14

x,y,radius Specifies the coordinates of the circle center and the radius (for shape="circle")

x1,y1,x2,y2,..,xn,yn Specifies the coordinates of the edges of the polygon. If the first and last coordinate
pairs are not the same, the browser will add the last coordinate pair to close the
polygon (for shape="poly")

href specifies the hyperlink target for the area.

Value Description

URL ossible values:


n absolute URL - points to another web site (like
href="http://www.example.com/sun.htm")
relative URL - points to a file within a web site (like href="sun.htm")
Page No:15

PROGRAM

Map.html:

<html>
<body>
<map name="picture">
<area href="Gujarat.html"shape="rect"coords="200,223,80,193"alt="mainpage"></area>
<area href="Kashmir.html"shape="circle"coords="270,60,33"alt="go to homepage"></area>
<area href="Madhya.html"shape="rect"coords="303,279,133,143"alt="Welcome">
</area>
</map>
<img src="indiamap.jpg"width="800"height="480"usemap="#picture">
</body>
</html>

Gujarat.html

<html>
<head>
<title>Gujarat</title>
</head>
<body style="background-color:purple">
<p style="font-family:arial;color:red;font-size:30px">welcome to gujarat</p>
<img src="7.jpg"alt="bigsize"width="550"height="400">
<p style ="font-family:arial;color:green;font-size:30px">tourist spots
<ul>
<li>power plants</li>
<li>national park</li>
<li>wild forests</li>
</ul>
</body>
</html>

Kashmir.html

<html>
<head>
<title>Kashmir</title>
</head>
<body style="background-color:green">
<p style=font-family:arial;color:red,font-size:30px">Welcome to Kashmir</p>
<img src="8.jpg"alt="bigsize"width="550"height="400">
<p style="font -family:arial;color:red;font-size30px">Tourist spots
<ul>
<li>Shimla</li>
<li>Snow mountains</li>
<li>Dhal lake</li>
</ul></p>
Page No:16

</body>
</html>

Madhya.html

<html>
<head>
<title> MadhyaPradesh</title>
</head>
<body style="background-color:blue">
<p style="font-family:arial;color:pink; font-size:30px"> Welcome to MadhyaPradesh</p>
<img src="9.jpg" alt="bigsize"width="550" height="400">
<p style="font-family:arial; color:red; font-size:30px"> Tourist spots
<ul>
<li>Bhopal</li>
<li>Gwalior</li>
<li>Jabalpur</li>
</ul></p>
</body>
</html>

OUTPUT

Map.html
Page No:17

Gujarat.html

Kashmir.html
Page No:18

Madhya.html

RESULT
Thus the html program to create web pages by embedding image map, fixing hotspots
and other related information was executed and output was verified.
Page No:19

EX. NO:3 CASCADING STYLE SHEETS- INLINE, EMBEDDED AND EXTERNAL


DATE:
AIM
To Create a web page with Cascading style sheets- Inline style, Embedded style sheets.
and External style sheets. Use our college information for the web pages.

ALGORITHM:
1. Start the program.
2. Create a web page with basic html tags
3. Define Inline Style within tag using style attribute
4. Define Internal Style within Style tag of Head tag
5. Define an external style sheets.
6. Make a link to the external style sheet.
7. Stop the program.

DESCRIPTION:
CSS stands for Cascading Style Sheets

Styling can be added to HTML elements in 3 ways:

 Inline - using a style attribute in HTML elements


 Internal - using a <style> element in the HTML <head> section
 External - using one or more external CSS files

CSS Syntax

 CSS styling has the following syntax:


 element { property:value; property:value }

Inline Styling (Inline CSS)

Inline styling is useful for applying a unique style to a single HTML element:Inline styling uses
the style attribute. This inline styling changes the text color of a single heading:

Example

<h1 style="color:blue">This is a Blue Heading</h1>

External Styling (External CSS)

External style sheet are ideal when the style is applied to many pages.
Page No:20

With external style sheets, you can change the look of an entire web site by changing one file.

Example:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

Embedded styling:

Embedded Style Sheets refer to when you embed style sheet information into an HTML document
using the<style> element. You do this by embedding the style sheet information within
<style></style> tags in the head of your document.
Example:
<style type="text/css" media=screen>
p {font-family: georgia, serif; font-size: x-small;}
hr {color: #ff9900; height: 1px }
a:hover {color: #ff0000; text-decoration: none}
</style>
Page No:21

PROGRAM:

inline.html
<html>
<head>
<title>CSS</title>
</head>
<body bgcolor=beige text=beige>
<!--Here Inline CSS is used-->
<h1 style = "color:blue; font-family:Calibri;
background-color:lightgray; border-style:solid; border-color:black;"
align=center>
Anand Institute of Higher Technology
</h1>
<!--Here Inline CSS is used-->
<marquee style= "font-family:LUCIDA BRIGHT; color:indigo"><i>Where everyday is a
placement day!!!!</i></marquee>
------<a href="Css2.html">Courses Offered</a>
------<a href="Css2.html">Placement</a>
------<a href="Css2.html">Facilities</a>
------<a href="Css3.html">About Us</a>
<img src="Picture1.gif">
<p style = "color:DarkTurquoise" >AIHT © 2014. All Rights Reserved.</p>
</body>
</html>

Embedded.html
<html>
<head>
<!--Here Internal CSS is used-->
<style>
h1 {color:blue; font-family: Calibri;
background-color:lightgray; border-style:solid; border-color:black}
h3 {color:orange; font-family:Bell MT;}
h2 {color:CadetBlue; font-family:SEGOE UI;}
li {color:green}
</style>
</head>
<body bgcolor=snow>
<h1 align=center>Anand Institute of Higher Technology</h1>
<h3>Courses Offered</h3>
<h2>Under Graduate Programmes</h2>
<ul>
<li> B.E. (Computer Science and Engineering)
<li> B.Tech. (Information Technology)
<li> B.E. (Electronics and Communication Engineering)
<li> B.E. (Mechanical Engineering)
<li> B.E. (Electrical and Electronic Engineering)
Page No:22

<li> B.E. (Civil Engineering)


</ul>
<h2>Post Graduate Programmes</h2>
<ul>
<li> M.C.A. (Master of Computer Applications)
<li> M.B.A. (Master of Business Administration)
<li> M.E. ( Communication Systems)
<li> M.E. ( Computer Science )
<li> M.E. ( Power Electronics and Drives)
<li> M.E. ( VLSI Design)
<li> M.E-(Embedded System Technologies)
</ul>
AIHT © 2014. All Rights Reserved.
</body>
</html>

external.html
<html>
<head>
<!--Here External CSS is used-->
<link rel="stylesheet type="text/css" href="web.css">
</head>
<body text=indigo bgcolor=linen>
<h1 align=center>Anand Institute of Higher Technology</h1>
<i><marquee>Where everyday is a placement day!!!!</marquee></i>
<p>Contact us<br><br>
Anand Institute of Higher Technology<br>Kalasalingam Nagar,<br>IT Corridor, Old
Mahablipuram Road,<br>Kazhipattur ,<br>Chennai-603103.<br>
[email protected]<br>
</p>
AIHT © 2014. All Rights Reserved.
</body>
</html>

Web.css
p{
color:brown; font-family:Comic Sans Ms; background-color:honeydew;
border-style:groove; border-color:red;}

h1 {
color:blue; background-color:lightgray;
border-style:solid; border-color:black;}

marquee {font-family:LUCIDA BRIGHT;}


Page No:23

OUTPUT:

RESULT
Thus the DHTML program to demonstrate the use of a web page with Cascading style
sheets- Inline style, Embedded style sheets. and External style sheets. was executed and the
output was verified.
Page No:24

EX. NO:4 USER REGISTRATION VALIDATION USING JAVASCRIPT


DATE:

AIM

To validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.

ALGORITHM

1) Start the program.


2) Create Main.html file.
3) Create frames for Online Book Storage.
4) Create separate html file for separate hotspots.
5) Link Top.html, Right.html, Left.html, Login.html, Profile.html, Scart.html,
Catalog.html, Payment.html, Order.html.
6) Validate the user login and payments.
7) Finally terminate the program and embed webpage.

PROGRAM
• Home page:
Main.html:
<frameset rows=”25%, 75 %”>
<frame src=”top.html” name=”top”>
<frameset cols=”25%,75%”>
<frame src=”left.html” name=”left”>
<frame src=”right.html” name=”right”>
</frameset>
</frameset>
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 bgcolor=”pink”>
<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>
Page No:25

</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”><fontcolor=”black”> USER
PROFILE</font></a></li><br>
<br>
<li><a href=”catalog.html” target=”right”><fontcolor=”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”><fontcolor=”black”>
PAYMENT</font></a></li><br><br>
<li><a href=”order.html” target=”right”><font color=”black”> ORDER
CONFIRMATION</font></a>
</li><br><br>
</ul>
</body>
</html>
Registration and user Login
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=="")
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
Page No:26

}
</script>
<form name="myform">
<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" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</form>
</body>
</html>
User profile page
Profile.html:
<html>
<body bgcolor=”pink”><br><br>
<script language=”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==””)
{
flag=0;
}
var str=document.myform.phno.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
Page No:27

else
{
alert("INVALID INPUT");
document.myform.focus();
}}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input type="type"
name="addr"><br>
CONTACT NUMBER:<iput type="text" name="phno"><br> LOGINID :<input type="text"
name="id">
<br> 19
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;
<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")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->c"+" cost-->444");
}
else if(str=="jsp")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->jsp"+" cost-->555");
}
else
{
flag=0;
Page No:28

}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" >
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br> 21
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</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==""||
document.myform.date.value=="")
{
flag=0;
}
var str=document.myform.no.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
Page No:29

if(!(x<=9))
{
flag=0;
break;
}
}
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" >
<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>
DATE :<input type="text" name="date"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</form>
</body>
</html>
Payment by credit card
Payment.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
Page No:30

{
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;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.num.value;
for(var i=0;i<str.lenght;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
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
Page No:31

type="PASSWORD"
name="num+"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</form>
</body>
</html>
Order Conformation
Order.html:
<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>
Page No:32

OUTPUT
Page No:33
Page No:34

RESULT
Thus the JavaScript program to validate the Registration, user login, user profile and
payment by credit card pages was executed and the output was verified.
Page No:35

EX NO: 5A Invoke Servlet from HTML


Date:
AIM
To invoke the Servlet from a HTML Program.

ALGORITHM
1. Create a HTML Program with two textboxes for name and age inside a form.
2. In the form action attribute, use the servlet name as the target.
3. Create a button and use it as a submit option.
4. When the submit button is clicked, the servlet is invoked.
5. Use the request object to retrieve the name and age typed in the textbox.
6. Display them when the servlet is invoked.
7. Terminate the program.

PROGRAM
Newhtml.html
<html>
<body>
<form action="gotoservlet1" method="get"><center>
Name:<input type="text" name="uname"/><br><br>
Age:<input type="text" name="uname2"/>
<input type="submit" value="submit"/></center>
</form>
</body>
</html>
gotoservlet1.java
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 gotoservlet1 extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet gotoservlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+request.getParameter("uname")+ "</h1>");
out.println("<h1>"+request.getParameter("uname2")+ "</h1>");
out.println("</body>");
Page No:36

out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Page No:37

OUTPUT

RESULT
Thus the program to invoke the Servlet from a HTML Program was executed and the
output was verified
Page No:38

EX NO: 5B INVOKE SERVLET FROM APPLET


AIM
To invoke the servlet from an Applet Program.

ALGORITHM
1. Create a HTML Program with a button inside a form.
2. In the form action attribute, use the Applet class name as the target.
3. Create a button and use it as a submit option.
4. When the submit button is clicked, the applet is invoked.
5. Use the applet’s button and add a action listener to it to invoke the servlet.
6. Give the full URL of the servlet to invoke it when the button is clicked.
7. Terminate the program.

PROGRAM CODE:
Newhtml.html
<html>
<head>
<title>Invoking Servlets From Applet</title>
</head>
<body>
<applet code="NewApplet.class" width="400" height="200">
</applet>
</body>
</html>
NewApplet.java
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NewApplet extends Applet
{ public void init() {
Button click = new Button("ok");
add(click);
click.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e)
{ try {
getAppletContext().showDocument(new
URL("http://localhost:8080/serap/NewServlet"));
}
Page No:39

catch (MalformedURLException ex)


{ Logger.getLogger(NewApplet.class.getName()).log(Level.SEVERE, null, ex);
}
}

});
}}
NewServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */ out.println("<!
DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
Page No:40

}// </editor-fold>
}
OUTPUT

RESULT
Thus the program to invoke the servlet from an Applet Program was executed and the
output was verified.
Page No:41

EX NO: 6 ONLINE EXAM USING SERVLETS


Date:
AIM
To create an online exam using the java servlet programming.

ALGORITHM
1. Create a JSP program to design an online quiz exam.
2. Use two text boxes for getting the seat number and the name.
3. Print the questions and use the radio buttons along with its group to add answers.
4. Invoke the servlet when the submit button is clicked.
5. In the servlet, read all the data from the JSP including the text boxes and the radio
buttons.
6. Create a new database and the table for online quiz registration.
7. Use the Statement, connection and Driver Manager object to get the connection to
the java DB and connect to the database to update the values.
8. Execute the insert query and store the values of the answers in the database.
9. Evaluate the whole quiz and print the output mark.
10. Terminate the program.

PROGRAM
Index.jsp
<html>
<head><title>Database Test</title></head>
<body>
<center>
<h1>SJIT Online Examination</h1>
</center>
<form action="action" method="POST">
<div align="left"><br></div>
<b>Seat Number:</b> <input type="text" name="Seat_no">
<br><br><br>
<b>Name:</b> <input type="text" name="Name" size="50"><br>
</div>
<br><br>
<b>1. TCP is reliable compared to UDP.</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<b>2. IP stands for Internet Programming</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<b>3. Web Technology is same as Internet Programming</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<b>4. Internet Programming includes web designing.</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<b>5. HTML stands for Hypertext Markup Language.</b><br/>
Page No:42

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


<input type="radio" name="group5" value="False">False<br>
<br><br><br>
<center>
<input type="submit" value="Submit"><br><br>
</center>
</form>
</body>
</html>
action.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/action"})
public class action extends HttpServlet {
String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5;
int Total=0;
java.sql.Connection connect;
java.sql.Statement stmt=null;
java.sql.ResultSet rs=null;
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try (PrintWriter out = response.getWriter()) {
String
url="jdbc:derby://localhost:1527/student;create=true;user=student;password=student";
try {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
connect=DriverManager.getConnection(url,"student","student");
message="Thank you for participating in online Exam";
Seat_no=request.getParameter("Seat_no");
Name=request.getParameter("Name");
ans1=request.getParameter("group1");
ans2=request.getParameter("group2");
ans3=request.getParameter("group3");
ans4=request.getParameter("group4");
ans5=request.getParameter("group5");
if(ans1.equals("True"))
Page No:43

Total+=1;
if(ans2.equals("True"))
Total+=1;
if(ans3.equals("False"))
Total+=1;
if(ans4.equals("True"))
Total+=1;
if(ans5.equals("True"))
Total+=1;
stmt=connect.createStatement();
String query="INSERT INTO
STUDENT.student(seatno,name,total)VALUES('"+Seat_no+"','"+Name+"',"+Total+")";
stmt.executeUpdate(query);
stmt.executeUpdate(query);
stmt.close();
response.setContentType("text/html");
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body bgcolor=gray>");
out.println("<center>");
out.println("<h1>"+message+"</h1>\n");
out.println("<h3>Yours results stored in our database</h3>");
out.print("<br><br>");
out.println("<b>"+"Participants and their Marks"+"</b>");
out.println("<table border=5>");
java.sql.Statement stmt2=connect.createStatement();
String query1="SELECT * FROM student";
rs=stmt2.executeQuery(query1);
out.println("<th>"+"Seat_no"+"</th>");
out.println("<th>"+"Name"+"</th>");
out.println("<th>"+"Marks"+"</th>");
while(rs.next())
{
out.println("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.println("</tr>");
}
out.println("</table>");
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(connect!=null)
Page No:44

connect.close();
out.println("</center>");
out.println("</body></html>");
Total=0;
} catch (InstantiationException ex)
{ Logger.getLogger(action.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex)
{ Logger.getLogger(action.class.getName()).log(Level.SEVERE, null, ex);
}
catch (ClassNotFoundException ex)
{ Logger.getLogger(action.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SQLException ex)
{ Logger.getLogger(action.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

OUTPUT
Page No:45

RESULT
Thus the program to create an online exam using the java servlet programming was
executed and the output was verified
Page No:46

EX NO: 7 INSTALL TOMCAT WEB SERVER(static webpages into dynamic webpages)


Date:

AIM:
To Install TOMCAT web server. Convert the static webpages into dynamic webpages
using servlets 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.

PROCEDURE:

1) First install the tomcat into the system.


2) Then make a subdirectly(eg., tr) in the \tomcat\webapps.
3) Under tr create WEB-INF directory and also place the html files in this tr directory
only.
4) Next under WEB-INF create two subclasses lib,classes and web.xml
5) Next place all the class files under the classes and jar files(servlet-api.jar,classes12.jar
etc…) under lib
6) subdirectories.
7) After this start tomcat by giving the following command at the
instll_dir>tomcat>bin Catalina.bat run
8) At the I.E(web browser) give the url as http;//localhost:8080//tr/htmlfile or servlet url
pattern
9) Portno 8080 is assigned for the tomcat.

PROGRAM

Home page:

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>
Page No:47

Login page:
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" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Registration page:
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 />
Page No:48

<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
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()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
Catalog.html:
<html>
<body><br /><br /><br />
<form method="post" action="catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body>
</html>
Shopping cart, Payment by credit card, Order
Conformation page:
Order.html:
<html>
Page No:49

<body><br /><br />


<form method="post" action="order">
<div align="center"><pre>
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;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form></body></html>
Login servlet :
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>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
Page No:50

while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
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>VALID LOGIN ID<br><br>"); 58
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());
}
}
}
Registration servlet:
Reg.java :
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
Page No:51

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");
int no=Integer.parseInt(phno);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(1))&&pwd1.equals(rs.getString(2)))
{
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+"',"+no+",'"+id1+"','"+pwd1+"')
;");
pw.println("<br><br>YOUR DETAILS ARE
ENTERED<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to
login</a>");
Page No:52

}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

Profile servlet:
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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","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)
Page No:53

{
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());
}
}
}
Catalog servlet:
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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc: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.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>");
Page No:54

pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID TITLE TRY
AGAIN <br><br>");
pw.println("<a href=\"catalog.html\">press HERE to
RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order servlet:
Order.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
int count;
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String title=req.getParameter("title");
String count1=req.getParameter("no");
String date=req.getParameter("date");
String cno=req.getParameter("cno");
try
{
count=Integer.parseInt(count1);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
Page No:55

String sqlstmt="select id,pwd 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;
}
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href= \" order.html \" >press HERE to RETRY</a>");
}
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)
{
Page No:56

resp.sendError(500,e.toString());
}
}
}
Web.xml:
<?xml version="1.0"?>
<web-app >
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>/reg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>/profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>/order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog</url-pattern>
Page No:57

</servlet-mapping>
<welcome-file-list>
<welcome-file>main.html</welcome-file></welcome-file-list>
</web-app>

OUTPUT
Page No:58
Page No:59

RESULT
Thus the program to Install TOMCAT web server was executed and the output was
verified.
Page No:60

EX.NO: 8 REDO THE PREVIOUS TASK USING JSP


Date:

AIM

To Redo the previous task using JSP by converting the static web pages of assignments 2
into dynamic web pages.
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:8081/tr1/main.html

PROGRAM
Home page:
Main.html:
<html>
<body>
<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="login.html">LOGIN</a>
<a href="reg.html">REGISTRATION</a></div></pre>
</body></html>
Login page:
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login.jsp">
<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" onclick="validate()" />
Page No:61

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />


</div>
</form>
</body>
</html>
Registration page:
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg.jsp">
<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()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
Profile.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile.jsp">
<div align="center"><pre>
Page No:62

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


</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
Catalog.html:
<html>
<body><br /><br /><br />
<form method="post" action="catalog.jsp">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body> </html>
Shopping cart, Payment by credit card, Order
Conformation page:
Order.html:
<html>
<body><br /><br />
<form method="post" action="order.jsp">
<div align="center"><pre>
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>
Page No:63

<br /><br />


<div align="center">
<input type="submit" value="ok" name="button1"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>
Login JSP:
Login.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
out.println("<a href=\"login.html\">press LOGIN to
RETRY</a>");
}
else
{
out.println("<br><br>VALID LOGIN ID<br><br>"); out.println("<h3><ul>");
out.println("<li><a
href=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font>
</a></li><br><br>");
out.println("<li><a
href=\"catalog.html\"><fontcolor=\"black\">BOOKS
Page No:64

CATALOG</font></a></li><br><br>");
out.println("<li><a
href=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font>
</a></li></ul><br><br>");
}
out.println("</body></html>");
con.close();
%>

Registration JSP:
Reg.jsp :
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% response.setContentType("text/html");
out.println("<html><body>");
String name=request.getParameter("name");
String addr=request.getParameter("addr");
String phno=request.getParameter("phno");
String id1=request.getParameter("id");
String pwd1=request.getParameter("pwd");
int no=Integer.parseInt(phno);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{ if(id1.equals(rs.getString(1))&&pwd1.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==1)
{ out.println("<br><br>SORRY INVALID ID ALREADY
EXITS TRY AGAIN WITH NEW ID<br><br>");
out.println("<a href=\"reg.html\">press REGISTER to
RETRY</a>");
}
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"');"); out.println("<br><br>YOUR
DETAILS
Page No:65

ARE
ENTERED<br><br>");
out.println("<a href=\"login.html\">press LOGIN to
login</a>");
}
out.println("</body></html>");
con.close();
%>
Profile JSP:
Profile.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+""; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
out.println("<br><br><br>");
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("NAME :"+rs.getString(1)+"<br>");
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("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
out.println("<a href=\"profile.html\">press HERE to
RETRY</a>");
}
out.println("</body></html>");
con.close(); %>
Catalog JSP:
Catalog.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
Page No:66

String title=request.getParameter("title");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc: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.next())
{
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;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID TITLE TRY
AGAIN <br><br>");
out.println("<a href=\"catalog.html\">press HERE to
RETRY</a>");
}
out.println("</body></html>");
con.close();
%>

Order servlet:
Order.java:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% int count;
out.println("<html><body>");
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");
count=Integer.parseInt(count1);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
Page No:67

con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd 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;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
out.println("<a href= \"order.html \" >press HERE to RETRY</a>");
}
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;
out.println("<br><br>AMOUNT
:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details
values('"+id+"','"+title+"',"+amount+",'"+cno+"');"); out.println("<br>YOUR ORDER has
taken<br>");
}
if(flag1==0)
{
out.println("<br><br><br>SORRY INVALID ID
TRY AGAIN ID<br><br>");
out.println("<a href=\"order.html\">press HERE to
RETRY</a>");
}
}
out.println("</body></html>");
con.close();
%>
Page No:68

OUTPUT:
Page No:69
Page No:70

RESULT
Thus the JSP program to redo the previous task by converting the static web pages of
assignments 2 into dynamic web pages was coded and the output was verified successfully.
Page No:71

EX. NO:9 CREATE AN XML DOCUMENT AND TAKE THE


DATE: INFORMATION FROM THE XML DOCUMENT

AIM
To write a program which takes user Id as an input and returns the user details by taking
the user information from the XML document.

ALGORITHM
1) start the program.
2) Create data.xml file and main.html file.
3) Get the user details in data.xml file.
4) Display all details in main.xml file.
5) Finally terminate the program and embed webpage.
PROGRAM
data.xml
<?xml version="1.0"?>
<data><user1>
<Name>Abi</Name>
<DOB> 31/07/1995</DOB>
<CellNo>7418823121</CellNo>
<Mailid>[email protected]</Mailid></user1>
<user2>
<Name>Ambika</Name>
<DOB> 03/06/1996</DOB>
<CellNo>7537883249</CellNo>
<Mailid>[email protected]</Mailid></user2>
<user3>
<Name>Divya</Name>
<DOB> 03/06/1996</DOB>
<CellNo>9994755116</CellNo>
<Mailid>[email protected]</Mailid></user3>
<user4>
<Name>Mariyaraj</Name>
<DOB> 26/05/1996</DOB>
<CellNo>7461278923</CellNo>
<Mailid>[email protected]</Mailid></user4>
<user5>
<Name>Muni</Name>
<DOB> 10/05/1996</DOB>
<CellNo>8098600869</CellNo>
<Mailid>[email protected]</Mailid></user5>
<user6>
<Name>Packiya Raj</Name>
<DOB> 09/04/1996</DOB>
<CellNo>9361012743</CellNo>
Page No:72

<Mailid>[email protected]</Mailid></user6>
<user7>
<Name>Ponna Karthi</Name>
<DOB> 24/12/1995</DOB>
<CellNo>7845714465</CellNo>
<Mailid>[email protected]</Mailid></user7>
<user8>
<Name>Push</Name>
<DOB> 31/07/1996</DOB>
<CellNo>9442405362</CellNo>
<Mailid>[email protected]</Mailid></user8>
<user9>
<Name>Sandle</Name>
<DOB> 31/03/1996</DOB>
<CellNo>9894436022</CellNo>
<Mailid>[email protected]</Mailid></user9>
<user10>
<Name>Sudhakaran</Name>
<DOB> 31/08/1996</DOB>
<CellNo>9443390912</CellNo>
<Mailid>[email protected]</Mailid></user10>
<user11>
<Name>Sasi</Name>
<DOB> 30/08/1995</DOB>
<CellNo>7548961563</CellNo>
<Mailid>[email protected]</Mailid></user11>
</data>
main.html
<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;
var y=window.prompt("enter user number",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>
Page No:73

OUTPUT

RESULT
Thus to write a program which takes user Id as an input and returns the user details by
taking the user information from the XML document was coded and the output was verified
successfully.
Page No:74

EX. NO: 10A DATA VALIDATION USING PHP

Date:

AIM
To validate the form using PHP regular expression
ALGORITHM:
1) start the program.
2) Insert all the expressions.
3) Using regular expression validate the email.
4) Finally terminate the program and embed webpage.

PROGRAM:
<?php
function valid_email($str) {
return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix",
$str)) ? FALSE : TRUE;
}
if(!valid_email("[email protected]")){
echo "Invalid email address.";
}else{
echo "Valid email address.";
}
?>

OUTPUT
Valid email address

RESULT
Thus the PHP program to validate the form was coded and the output was verified
successfully.
Page No:75

EX. NO: 10B STORES DATA USING PHP


AIM

To stores a form data into database using PHP.

ALGORITHM:
1) start the program.
2) Get the the data from user
3) Display the all data to another page.
4) Finally terminate the program and embed webpage.

PROGRAM
<html>
<head>
<title>insert data in form</title>
</head>
<body>
<form action = "getdata.php" method = "POST">
Name:
<input type = "text" name = "txtname">
<br><br>
Roll no.:
<input type = "text" name = "txtr_no">
<br><br>
Address:
<textarea name = "add" type = "textarea"></textarea>
<br><br>
Contyact No:
<input type = "text" name = "txtc_no">
<br><br>
Email ID:
<input type = "text" name = "txteid">
<br><br>
<input type = "Submit" name = "insert" value = "Save">
<input type = "Reset" value = "Cancle">
</form>
</body>
</html>
Getdata.php
<html>
<head>
<title>get data from another page</title>
</head>
<body>
<?php
Page No:76

echo "Name:" .$_POST["txtname"]."</br>";


echo "Roll no.:".$_POST["txtr_no"]."</br>";
echo "Address:".$_POST["add"]."</br>";
echo "Contact No.:".$_POST["txtc_no"]."</br>";
echo "Email ID:".$_POST["txteid"]."</br>";
?>
</body>
</html>
Page No:77

OUTPUT

RESULT
Thus the PHP program to stores a form data into database was coded and the output was
verified successfully.
Page No:78

EX NO.11 WEB SERVICE FOR OPINION FINDING


Date:

AIM:
To Write a web service for finding what people think by asking many people’s opinion
for a consumer product.

ALGORITHM:
1. Start the exercise by creating a html program for getting the feedback about
any particular product.
2. Use a textbox to get the name of the user and radio buttons to get the feedback rating
from 1-5.
3. Submit the details and proceed the recording of the details of the user in a servlet file.
4. Use the drivers and connection objects along with the statement objects to get the
connection and execute the insert query to insert the details of the user in a table.
5. Create a button to view all the records of the opinions that are registered by the users.
6. Terminate the program.

PROGRAM
index.html
<html>
<head>
</head>
<body>
<form action="back">
<center> <h2>Feedback on Sony Keyboard</h2> <br>
<img src="sony_vpcx_laptop_keyboard_key.jpg" width="400" height="100"><br>
<br>
Name: <input type="text" name="name"><br>
1.How was the ease of use of the product?<br>
<input type="radio" name="one" value="1"> 1
<input type="radio" name="one" value="2"> 2
<input type="radio" name="one" value="3"> 3
<input type="radio" name="one" value="4"> 4
<input type="radio" name="one" value="5"> 5<br><br>
2.How was the quality of the keys?<br>
<input type="radio" name="two" value="1"> 1
<input type="radio" name="two" value="2"> 2
<input type="radio" name="two" value="3"> 3
<input type="radio" name="two" value="4"> 4
<input type="radio" name="two" value="5"> 5
<br><br>
3. How was the response of the keys to the OS?<br>
<input type="radio" name="three" value="1"> 1
<input type="radio" name="three" value="2"> 2
<input type="radio" name="three" value="3"> 3
<input type="radio" name="three" value="4"> 4
Page No:79

<input type="radio" name="three" value="5"> 5<br><br>


<input type="submit" value="submit"><br>
</form>
<form action="display"><br>
<input type="submit" value="display">
</form> </center>
</body>
</html>

back.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/back"})
public class back extends HttpServlet
{ Connection connect;
ResultSet rs;
Statement st;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String name=request.getParameter("name");
String one=request.getParameter("one");
String two=request.getParameter("two");
String three=request.getParameter("three");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex)
{ Logger.getLogger(back.class.getName()).log(Level.SEVERE, null, ex);
}
try {
connect =
DriverManager.getConnection("jdbc:derby://localhost:1527/gift","gift","gift");
st=connect.createStatement();
Page No:80

//st.executeUpdate("INSERT INTO GIFT.OPINION VALUES


('"+name+"'"+one+"'"+two+"'"+three+")");
st.executeUpdate("insert into GIFT.OPINION
values('"+name+"','"+one+"','"+two+"','"+three+"')");
//stmt.executeUpdate("insert into emp values('"+eid+"','"+name+"','"+sal+"')");
} catch (SQLException ex)
{ Logger.getLogger(back.class.getName()).log(Level.SEVERE, null, ex);
}
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet back</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1><center> Feed back recorded</h1>");
out.println("<a href=\"index.html\">back</a></center>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
display.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
Page No:81

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/display"})
public class display extends HttpServlet {
Connection connect;
ResultSet rs;
Statement st;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet display</title>");
out.println("</head>");
out.println("<body>");
out.println("<center>");
out.println("<h1>Opinion of Users registered<h1><br><br>");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex)
{ Logger.getLogger(back.class.getName()).log(Level.SEVERE, null, ex);
}
try {
connect =
DriverManager.getConnection("jdbc:derby://localhost:1527/gift","gift","gift");
st=connect.createStatement();
rs=st.executeQuery("select * from GIFT.OPINION");
while(rs.next())
{
out.print("<h4>Name: "+rs.getString("name"));
out.print("Comfort:" + rs.getString("one"));
out.print("Keys Quality:" + rs.getString("two"));
out.print("Response :" + rs.getString("three"));
}
} catch (SQLException ex)
{ Logger.getLogger(back.class.getName()).log(Level.SEVERE, null, ex);
}
out.println("<br><a href=\"index.html\"> back </a>");
out.println("</body>");
out.println("</html>");
}
Page No:82

}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Page No:83

OUTPUT
Page No:84

RESULT
Thus the program to develop the scenario of a web service for finding what people think
by asking many people’s opinion for a consumer product is written and executed successfully.
Page No:85

ADDITIONAL PROGRAMS
EXAMPLE FOR FORM VALIDATION USING JAVA SCRIPT

AIM:
To design a webpage to validate a form

ALGORITHM:

1. Create a simple HTML page.

2. Create control using input tag they are like name,gender, email id ,Date of birth, age,

qualification,Soft skills.

3. Using JavaScript we are going to validate each and every control after the submit button is

clicked so a Form1_Validator() us created.

4. Write the java script function to validate all mandatory fields on your web page.

5. Validation should be done after the submit operation.

6. Use appropriate tags to display the contents.

7. Make sure the page is working efficiently.

/**********************formvalidation.html****************************/
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="ext.css"/>
<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT>
function Form1_Validator(theForm)
{

if (theForm.fn.value == "")
{
alert("You must enter your name");
theForm.fn.focus();
return (false);
}
if (theForm.ln.value == "")
{
alert("You must enter your initial.");
theForm.ln.focus();
return (false);
}
if (theForm.Password.value.length < 5)
{
Page No:86

alert("Please enter at least 5 characters in the \"Password\" field.");


theForm.Password.focus();
return (false);
}

// check if both password fields are the same


if (theForm.Password.value != theForm.Password2.value)
{
alert("The two passwords are not the same.");
theForm.Password2.focus();
return (false);
}
if (theForm.ed.value == "")
{
alert("Please enter a value for the \"Email\" field.");
theForm.ed.focus();
return (false);
}
var checkEmail = "@.";
var checkStr = theForm.ed.value;
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkEmail.length; j++)
{
if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt = true;
if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod = true;
if (EmailAt && EmailPeriod)
break;
if (j == checkEmail.length)
break;
}
// if both the @ and . were in the string
if (EmailAt && EmailPeriod)
{
EmailValid = true
break;
}
}
if (!EmailValid)
{
alert("The \"email\" field must contain an \"@\" and a \".\".");
theForm.ed.focus();
return (false);
}
var radioSelected = false;
for (i = 0; i < theForm.gender.length; i++)
Page No:87

{
if (theForm.gender[i].checked)
radioSelected = true;
}
if (!radioSelected)
{
alert("Please select your gender");
return (false);
}
if (theForm.date_day.selectedIndex <=0)
{
alert("Please select a day.");
theForm.date_day.focus();
return (false);
}
if (theForm.date_month.selectedIndex <=0)
{
alert("Please select a month.");
theForm.date_month.focus();
return (false);
}
if (theForm.date_year.selectedIndex <=0)
{
alert("Please select a year.");
theForm.date_year.focus();
return (false);
}
if (theForm.ta.value=="")
{
alert("Please enter your contact address");
theForm.ta.focus();
return (false);
}
if (theForm.ta.value.length > 150)
{
alert("Please enter at most 150 characters in the comment field.");
theForm.ta.focus();
return (false);
}
if(document.frmTest.C1.checked == false && document.frmTest.C2.checked == false &&
document.frmTest.C3.checked == false)
{
alert ('You didn\'t choose any of the qualification discipline!');
return false;
}
var numSelected = 0;
var i;
for (i = 0; i < theForm.SKILLS.length; i++)
{
if (theForm.SKILLS.options[i].selected)
numSelected++;
}
Page No:88

if (numSelected < 1)
{
alert("Please select at least one of the skill.");
theForm.SKILLS.focus();
return (false);
}
}
</SCRIPT>
</head>
<body>
<CENTER><h1>ANAND INSTITUTE OF HIGHER TECHNOLOGY</h1>
<h1>KAZHIPATTUR</h1>
<H1>REGISTRATION FORM</H1></CENTER>
<FORM onsubmit="return Form1_Validator(this);" name="frmTest" action="D:/balaji AS-WEB
LAB/EX3A&B/Y.html" method="post">
<P id="formlocation">
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname" name="fn"><BR>
<LABEL for="lastname" >INITIAL: </LABEL>
<INPUT type="text" id="lastname" name="ln"><BR>
Password:
<input type="password" size="10" maxlength="10" name="Password">

Verify Password:
<input type="password" size="10" maxlength="10" name="Password2"><br>
2 checks: Require at least 5 characters in the first password field.
Check if both password field values are the same.<BR>
<LABEL for="email id ">email id: </LABEL>
<INPUT type="text" id="email" name="ed"><BR>
<INPUT type="radio" name="gender" value="Male"> Male<BR>
<INPUT type="radio" name="gender" value="Female">Female<BR>
<LABEL for="DOB">DATE OF BIRTH</LABEL>
<select name="date_day">
<option value="DD">0</option>
<option value="DD">1</option>
<option value="DD">2</option>
<option value="DD">3</option>
<option value="DD">4</option>
<option value="DD">5</option>
<option value="DD">6</option>
<option value="DD">7</option>
<option value="DD">8</option>
<option value="DD">9</option>
<option value="DD">10</option>
<option value="DD">11</option>
<option value="DD">12</option>
<option value="DD">13</option>
<option value="DD">14</option>
<option value="DD">15</option>
<option value="DD">16</option>
<option value="DD">17</option>
<option value="DD">18</option>
Page No:89

<option value="DD">19</option>
<option value="DD">20</option>
<option value="DD">21</option>
<option value="DD">22</option>
<option value="DD">23</option>
<option value="DD">24</option>
<option value="DD">25</option>
<option value="DD">26</option>
<option value="DD">27</option>
<option value="DD">28</option>
<option value="DD">29</option>
<option value="DD">30</option>
<option value="DD">31</option>
</select>
<select name="date_month">
<option value="MM">0</option>
<option value="MM">JAN</option>
<option value="MM">FEB</option>
<option value="MM">MAR</option>
<option value="MM">APR</option>
<option value="MM">MAY</option>
<option value="MM">JUN</option>
<option value="MM">JUL</option>
<option value="MM">AUG</option>
<option value="MM">SEP</option>
<option value="MM">OCT</option>
<option value="MM">NOV</option>
<option value="MM">DEC</option>

</select>
<select name="date_year">
<option value="YY">0</option>
<option value="YY">1983</option>
<option value="YY">2001</option>
<option value="YY">2002</option>
<option value="YY">2003</option>
<option value="YY">2004</option>
<option value="YY">2005</option>
<option value="YY">2006</option>
<option value="YY">2007</option>
<option value="YY">2008</option>
<option value="YY">2009</option>
<option value="YY">2010</option>
<option value="YY">2011</option>
<option value="YY">2012</option>

</select><BR>
ENTER YOUR ADDRESS<BR><textarea rows="4" cols="20" name="ta">
</textarea><BR>
<LABEL for="QUALI">QUALIFICATION DISCIPLINE</LABEL><BR>
<INPUT TYPE=CHECKBOX name="C1">ENGINEERING<BR>
<INPUT TYPE=CHECKBOX name="C2">ARTS AND SCIENCE<BR>
Page No:90

<INPUT TYPE=CHECKBOX name="C3">DIPLOMA<BR>

<LABEL for="SK">SELECT YOUR SOFT SKILLS</LABEL><BR>


<SELECT NAME="SKILLS" MULTIPLE SIZE="5">
<OPTION VALUE="o1">C
<OPTION VALUE="o2">C++
<OPTION VALUE="o3">JAVA
<OPTION VALUE="o4">.NET
<OPTION VALUE="o5">J2EE
<OPTION VALUE="o5">J2ME
</SELECT><BR>

<INPUT type="submit" value="Submit" name="submit" >


<INPUT type="reset" value="reset" name="reset">
</P>
</FORM>
</body>
</HTML>
Page No:91

RESULT:
Thus the HTML page using java script to design a webpage to validate a form
was executed successfully.
Page No:92

EXAMPLE FOR SERVLET PROGRAM

AIM:
To write a simple servlet program using HTTP in java.

ALGORITHM:

1. Create a Servlet program using HttpServlet

2. Using doPost method we create objects using HttpServletRequest and HttpServletResponse

3. Set content type has text/html

4. Create output object by using PrintWriter class.

5. Then Set classpath where servlet-api.jar file resides.

Example path: C:\Tomcat\apache-tomcat-5.5.28\common\lib\servlet-api.jar

6. Compile the Servlet program using javac programname.java

7. Create a folder Servlet under that create folder WEB-INF inside create a folder named classes

where the WelcomeServlet.class should be placed

8. Inside WEB-INF place the web.xml file i.e. the deployment descriptor file

9. The form.html file should be placed in the Servlet folder

10. Modify the web.xml file using your servletClassName.

11. Invoke the class file using http://localhost:8080/Servlet/form.html from your browser
Page No:93

/**************************form.html***********************************/

<html>

<head>
<title>The servlet example </title>
</head>
<body background="ELECTION.jpg">
<font size="15" color="black"><h1>VOTE FOR RIGHT CANDIDATE</h1></font>
<form method="POST" action="WelcomeServlet">
<font size="10" color="red">

<label for="name">Enter your Name </label>


<input type="text" id="name" name="name"/><br><br>
<label for="name">Enter your Age </label>
<input type="text" id="age" name="age"/><br><br>
<input type="submit" value="Submit Form"/>
<input type="reset" value="Reset Form"/>
</font>
</form>
</body>
</html>

/**************************WelcomeServlet.java***********************************/

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WelcomeServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
String name = request.getParameter("name");
String welcomeMessage = "Welcome "+name;
String age = request.getParameter("age");
int age1=Integer.parseInt(age);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> A very simple servlet example</title>");
out.println("</head>");
out.println("<body background='VOTE.jpg'>");
out.println("<h1>"+welcomeMessage+"</h1>");
if(age1>=18)
out.println("<H2>GOOD LUCK ,YOU ARE ELIGIBLE TO VOTE</H2>");
Page No:94

else
out.println("<H2>SORRY,YOU ARE NOT ELIGIBLE TO VOTE</H2>");
out.println("<a href=/Servlet/form.html>"+"Click here to go back to input page "+"</a>");
out.println("</body>");
out.println("</html>");
out.close();
}
}

/****************************web.xml***********************************/
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/WelcomeServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file> /Servlet/form.html </welcome-file>
</welcome-file-list>
</web-app>
Page No:95

RESULT:

Thus the simple servlet program using HTTP in java was executed Successfully.
Page No:96

EXAMPLE FOR JSP WITH SESSION AND COOKIES


ONLINE PIZZA ORDER USING JSP WITH SESSION AND COOKIES

AIM:
To create a online pizza order using jsp with session and cookies.

ALGORITHM:

1. Create a login page using html.username and passwords are verified by loginverify.jsp. If the

username and password are not correct the page is forwarded to invalid.html.

2. If the username and password are not correct the page is forwarded to the jsp page is EX5A.jsp.

3. Create a jsp page to generate pizza order form.

4. If the No.of pizza,place are valid then the page is forwarded to avail.html.

5. If the No.of pizza,place are not valid then the page is forwarded to notavail.html.

6. Create session and cookies in appropriate jsp page.

7. Stop

/**************************Login.html********************************/

<html>
<link rel="stylesheet" type="text/css" href="ddd.css"/>
<script>
function show(theForm)
{
if((theForm.un.value == "") && (theForm.pw.value == ""))
{
alert("enter the user name AND password");
return false;
}
if(theForm.un.value == "")
{
alert("enter the user name");
return false;
}
if(theForm.pw.value == "")
{
alert("enter the password");
return false;
}
Page No:97

}
</script>
<body>
<marquee><font size="26" color="blue"> HEALTH IS WEALTH </font></marquee>
<center>
<h1>
<form method="POST" onsubmit="return show(this);" action="loginverify.jsp" name="Tick">
<marquee><font size="26" color="339933"> TOO MUCH OF ANYTHING IS NOT
GOOD</font></marquee>
<p id="formlocation">
<font size="20" color="pink">CELEBRATION STARTS NOW</font><br>
USER NAME:<input type="text" size="11" id="unate" name="un"><br><br>
PASSWORD:<input type="password" size="20" id="pwate" name="pw"><br><br>

<input type="submit" name="sub"><br><br>


</p>
</form>
</h1>
</center>
</body>
</html>
/***************************loginverify.jsp********************************/

<%@ page language="java" import="java.util.*"%>


<html>
<body>
<%
String username=request.getParameter("un");
String password=request.getParameter("pw");
if(username.equals("balaji") && password.equals("franko"))
{
session.setAttribute("username",username);
Cookie cookie = new Cookie ("username",username);
cookie.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(cookie);
response.sendRedirect("EX5A.jsp");
}
else
{
response.sendRedirect("invalid.html");
}
%>
</body>
</html>

/*************************invalid.html*********************************/

<html>
<body>
<h1>user name and password are not correct</h1>
<a href="login.html">click here to go login page</a>
</body>
Page No:98

</html>
/**************************EX5A.jsp***********************************/
<html>
<link rel="stylesheet" type="text/css" href="ddd.css"/>
<script>
function show(theForm)
{
if((theForm.pz.value == "") && (theForm.pc.value == ""))
{
alert("ENTER THE No.of PIZZA AND YOUR PLACE");
return false;
}
if(theForm.pz.value == "")
{
alert("ENTER THE No.of PIZZA");
return false;
}
if(theForm.pc.value == "")
{
alert("ENTER YOUR PLACE");
return false;
}
if (theForm.ta.value.length > 150)
{
alert("Please enter at most 150 characters in the comment field.");
theForm.ta.focus();
return (false);
}
}
</script>
<body>
<marquee><font size="26" color="blue"> HEALTH IS WEALTH </font></marquee>
<center>
<h1>
<form method="POST" onsubmit="return show(this);" action="pizza.jsp" name="Tick">
<marquee><font size="26" color="339933"> TOO MUCH OF ANYTHING IS NOT GOOD FOR
HEALTH</font></marquee>
<p id="formlocation">
<font size="20" color="green">ONLINE PIZZA ORDER<BR> CELEBRATION STARTS
NOW</font><br>
<font size = 6>Hello</font> <%= session.getAttribute("username") %><br>
ENTER THE NO.OF PIZZA:<input type="text" size="11" id="pzate" name="pz"><br><br>
ENTER YOUR PLACE:<input type="text" size="20" id="pcate" name="pc"><br><br>
ENTER YOUR ADDRESS<BR><textarea rows="8" cols="40" name="ta">
</textarea><BR>
<input type="submit" name="sub"><br><br>
</p>
</form></h1></center>
</body></html>
/****************************notavail.html****************************/

<%@ page language="java" contentType="text/html"%>


Page No:99

<html>
<body bgcolor="YELLOW">

<font color="pink" size=30>YOUR REQUESTED NO.OF PIZZA ARE NOT


AVAILABLE</font><br><br>
<font color="RED" size=30>CURRENTLY NO.OF AVAILABLE PIZZA=50 </font><br><br>
<font color="green" size=30>OUR PIZZA SHOP BRANCHES AVAILABLE ONLY IN THE
FOLLOWING AREA</font><br><br>
<font color="BLACK" size=30>
<ol>
<li>kazhipattur
<li>padur
<li>kelambakkam
</ol></font><br>
<A HREF="EX5A.jsp">click here to go for pizza order page</A>
</body>
</html>

/******************************avail.jsp******************************/
<%@ page language="java" contentType="text/html"%>
<%
String cookieName = "username";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
break;
}
}
}
%>
<html>
<body bgcolor="green">
<font color="pink" size=30>YOUR REQUESTED NO.OF PIZZA ARE AVAILABLE</font><br><br>
<font color="YELLOW" size=30>WE WILL DELIVER YOUR PIZZA WITHIN 15
MINUTES</font><br><br>

<font color="RED" size=30>THANK YOU VERY MUCH</font><br>


<%
if (myCookie == null)
{
%>
No Cookie found with the name <%=cookieName%>
<%
}
Page No:100

else
{
%>
<h2><p>VISIT AGAIN: <%=myCookie.getValue()%></h2>
<%
}
%>
</body>
</html>
Page No:101
Page No:102
Page No:103

RESULT:

Thus the jsp program for online pizza order using jsp with session and cookies was
executed successfully.
Page No:104

EXAMPLE FOR DATABASE ACCESS


ONLINE APPLY FOR RECRUITMENT WITH DATABASE ACCESS

AIM:
To create a system for online apply for recruitment using access database.

ALGORITHM:

1. Create a simple recruithome.html HTML page.To get the username and password to generate

details about applicant.

2. The recruithome.html also has a link to recruit_registrationform.html.It is a registration form to get

information from such as name,gender,degree,experience etc.

3. Create a database connection using jsp connection.forname and drivermanager

4. Upload all these files into webapps folder of tomcat server

5. Using http://localhost:8080/foldername/filename.jsp we can execute the file in the web

browser

6. We have to create a database in access within that create a table name users and login with

the fields like usernsme and password.

/************************** recruithome.html******************************/
<html>
<link rel="stylesheet" type="text/css" href="ddd.css"/>
<script>
function show(theForm)
{
if((theForm.fd.value == "") && (theForm.td.value == ""))
{
alert("enter the USER NAME & PASSWORD");
return false;
}
if(theForm.fd.value == "")
{
alert("enter the USER NAME");
return false;
}
if(theForm.td.value == "")
{
Page No:105

alert("enter the PASSWORD");


return false;
}
}
</script>
<body>
<FONT COLOR="RED"><CENTER><h1>ANAND INSTITUTE OF HIGHER TECHNOLOGY</h1>
<h1>KAZHIPATTUR</h1></FONT>
<font color="green"><A HREF="http://localhost:8080/DB/recruit_registrationform.html"><H1>TO
APPLY ONLINE FOR RECRUITMENT (TEACHING FACULTY) CLICK HERE</H1></A></font>
<center>
<form onsubmit="return show(this);" action="http://localhost:8080/DB/display.jsp" method="post"
name="Tick">
<p id="formlocation">
<font size="20" color="YELLOW">ADMINISTRATOR LOGIN</font><br>
<font size="10" color="RED">USER NAME:<input type="text" size="11" id="fdate"
name="fd"><br><br>
PASS WORD:<input type="password" size="20" id="tdate" name="td"><br><br></font>
<input type="submit" name="sub"><br><br>
</p>
</form>
</h1>
</center>
</body>
</html>

/************************** recruit_registrationform.html************************/
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="ext.css"/>
<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT>
function Form1_Validator(theForm)
{

if (theForm.fn.value == "")
{
alert("You must enter your full name");
theForm.fn.focus();
return (false);
}

var radioSelected = false;


for (i = 0; i < theForm.gender.length; i++)
{
if (theForm.gender[i].checked)
radioSelected = true;
}
if (!radioSelected)
{
alert("Please select your gender");
Page No:106

return (false);
}

if (theForm.ed.value == "")
{
alert("Please enter your Email id");
theForm.ed.focus();
return (false);
}

var checkEmail = "@.";


var checkStr = theForm.ed.value;
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkEmail.length; j++)
{
if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt = true;
if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod = true;
if (EmailAt && EmailPeriod)
break;
if (j == checkEmail.length)
break;
}
// if both the @ and . were in the string
if (EmailAt && EmailPeriod)
{
EmailValid = true
break;
}
}
if (!EmailValid)
{
alert("The \"email\" field must contain an \"@\" and a \".\".");
theForm.ed.focus();
return (false);
}

if (theForm.cn.value == "")
{
alert("Please enter your contact number");
theForm.ed.focus();
return (false);
}

if (theForm.DEG.selectedIndex <=0)
{
Page No:107

alert("Please select your highest degree");


theForm.DEG.focus();
return (false);
}
if (theForm.spec.selectedIndex <=0)
{
alert("Please select your specialization");
theForm.spec.focus();
return (false);
}

if (theForm.year.value == "")
{
alert("Please enter your year of graduation");
theForm.year.focus();
return (false);
}

if (theForm.dur.selectedIndex <=0)
{
alert("Please select your mode of study");
theForm.spec.focus();
return (false);
}

if (theForm.te.value == "")
{
alert("Please enter your teaching experience");
theForm.year.focus();
return (false);
}

if (theForm.ie.value == "")
{
alert("Please enter your industrial experince");
theForm.ie.focus();
return (false);
}

if (theForm.ta.value.length =="")
{
alert("Please enter your address");
theForm.ta.focus();
return (false);
}

if (theForm.ta.value.length > 200)


{
alert("Please enter at most 150 characters in the comment field.");
theForm.ta.focus();
return (false);
}
Page No:108

}
</SCRIPT>
</head>
<body>
<CENTER><h1>ANAND INSTITUTE OF HIGHER TECHNOLOGY</h1>
<h1>KAZHIPATTUR</h1>
<H1>REGISTRATION FORM</H1>
<H2>RECRUITMENT FOR TEACHING FACULTY</H2></CENTER>
<FORM onsubmit="return Form1_Validator(this);" name="frmTest"
action="http://localhost:8080/DB/insert.jsp" method="post">
<P id="formlocation">
NAME:
<INPUT type="text" id="firstname" name="fn"><BR><BR>
GENDER:
<INPUT type="radio" name="gender" value="Male"> Male
<INPUT type="radio" name="gender" value="Female">Female<BR><BR>
EMAIL ID:
<INPUT type="text" id="email" name="ed"><BR><BR>
CONTACT NO:
<INPUT type="text" id="cont" name="cn" maxlength="10" ><BR><BR>

DEGREE(HIGHEST):
<select name="DEG">
<option value="0">0</option>
<option value="B.E">B.E</option>
<option value="B.TECH">B.TECH</option>
<option value="M.E">M.E</option>
<option value="M.TECH">M.TECH</option>
<option value="MCA">MCA</option>
<option value="PHD">PHD</option>
</select> <BR><BR>
SPECIALIZATION:
<select name="spec">
<option value="0">0</option>
<option value="CSE">CSE</option>
<option value="IT">IT</option>
<option value="ECE">ECE</option>
<option value="EEE">EEE</option>
<option value="EIE">EIE</option>
<option value="MECH">MECH</option>
<option value="MCA">MCA</option>
</select> <BR><BR>
YEAR OF GRADUATION:
<input type="text" size="4" maxlength="4" name="year"><BR><BR>
MODE OF STUDY:
<select name="dur">
<option value="0">0</option>
<option value="FULL TIME">FULL TIME</option>
<option value="PART TIME">PART TIME</option>
</select> <BR><BR>
TEACHING EXPERIENCE:
Page No:109

<INPUT type="text" id="te" maxlength="2" name="te"><BR><BR>


INDUSTRIAL EXPERINCE:
<INPUT type="text" id="ie" maxlength="2" name="ie"><BR><BR>
ENTER YOUR ADDRESS:<BR><textarea rows="8" cols="40" name="ta">
</textarea><BR>
</select> <BR><BR>
<INPUT type="submit" value="Submit" name="submit" >
<INPUT type="reset" value="reset" name="reset">
</body>
</HTML>
/*****************************ack.html**********************************/

<html>
<body background="thanks.gif">
<h1>YOUR REGISTRATION COMPLETED successfully </h1>
<font color="red"><h1>THANK YOU VERY MUCH</h1><br><br>
<h1>WE WILL SEND THE INTERVIEW DATE TO YOUR EMAIL ID</h1></font>
<font color="green">
<h1>while coming to interview you should bring all the
ORIGINAL CERTIFICATES</h1> </font><BR><BR>
<pre>
ANAND INSTITUTE OF HIGHER TECHNOLOGY
Kalasalingam Nagar, IT Corridor,
Old Mahabalipuram Road,
Kazhipattur,
Chennai - 603 103.
Phone : 044 - 27471320
044 - 27471330
Fax : 91-44-27471310
91-44-27471320
Mail Id : [email protected]
Website : http://www.aiht.ac.in

HEAD OFFICE
No:52(Old No.14) Sriman Srinivasan Road,
Alwarpet,
Chennai-600 018.
Phone : 044-24353053
Fax : 044-24331153
</pre>
</body>
</html>
Page No:110

/****************************display.jsp****************************************/
<html>
<body>
<%@page import="java.sql.*"%>
<%
String username=request.getParameter("fd");
String password=request.getParameter("td");
ResultSet rs;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:staff");
Statement st=con.createStatement();
rs=st.executeQuery("SELECT * FROM login");
while(rs.next())
{
String un=rs.getString(1);
String pw=rs.getString(2);
if ( (username.equals(un)) && (password.equals(pw)) )
{
response.sendRedirect("report.jsp");
}
else
{
out.println("CHECK YOUR USER NAME AND PASSWORD");%>
<a href="http://localhost:8080/DB/recruithome.html">BACK</a>
<%
}
}
}
catch(Exception e)
{
out.println("CONNECTION ERROR");
}
%>
</body>
</html>
/****************************insert.jsp****************************************/

<%@page import="java.sql.*"%>
<%
String name=request.getParameter("fn");
String gender=request.getParameter("gender");
String eid=request.getParameter("ed");
String contact=request.getParameter("cn");
String degree=request.getParameter("DEG");
String special=request.getParameter("spec");
String yr=request.getParameter("year");
String mode=request.getParameter("dur");
String teach=request.getParameter("te");
String indus=request.getParameter("ie");
Page No:111

String address=request.getParameter("ta");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:staff");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into user
values('"+name+"','"+gender+"','"+eid+"','"+contact+"','"+degree+"','"+special+"','"+yr+"','"+mode+"','"+te
ach+"','"+indus+"','"+address+"')");
response.sendRedirect("ack.html");
}
catch(Exception e)
{
out.println("CONNECTION ERROR");
}
%>

/****************************report.jsp***************************************/
<html>
<body>
<%@page import="java.sql.*"%>
<%
String username=request.getParameter("fd");
String password=request.getParameter("td");
ResultSet rs;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:staff");
Statement st=con.createStatement();
rs=st.executeQuery("SELECT * FROM user");
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;" align="center">
<TR>
<TD>NAME</TD>
<TD>GENDER</TD>
<TD>EMAIL ID</TD>
<TD>CONTACT NO</TD>
<TD>DEGREE(HIGHEST)</TD>
<TD>SPECIALIZATION</TD>
<TD>YEAR OF GRADUATION</TD>
<TD>MODE OF STUDY</TD>
<TD>TEACHING EXPERIENCE</TD>
<TD>INDUSTRIAL EXPERINCE</TD>
<TD>ENTER YOUR ADDRESS</TD>
</TR>

<%
while(rs.next())
{
%>
Page No:112

<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><%=rs.getString(5)%></TD>
<TD><%=rs.getString(6)%></TD>
<TD><%=rs.getString(7)%></TD>
<TD><%=rs.getString(8)%></TD>
<TD><%=rs.getString(9)%></TD>
<TD><%=rs.getString(10)%></TD>
<TD><%=rs.getString(11)%></TD>
</TR>

<% } %>
</TABLE>
<% }
catch(Exception e)
{
out.println("CONNECTION ERROR");
}
%>
</body>
</html>
Page No:113
Page No:114
Page No:115

RESULT:

Thus the jsp program for online apply for recruitment with Access database was
executed successfully
Page No:116

EXAMPLE FOR PHP


WEB APPLICATION DEVELOPED USING PHP

Aim

To create a web application using PHP.

Algorithm

1. Install PHP and wamp server.

2. Write a PHP program for web application and save it using .php extension.

3. Create the php program using <?php ?> tags under that declare variables using $variable name

for storing the information which we got from the HTML form and it will display in the same

page

4. After creating the php page store it in the calculator folder present inside the wamp Server and

then using call using http://localhost/calculator/calory_calc.php

5. Run the .php file in the web browser by specifying the path.

/***************************calory_calc.php******************************/
<html>
<body background="health.jpeg">
<center>
<head><h1><font face = "times new roman" color="green">CALORIE
CALCULATOR</font></h1></head>
<form method="post">
<h2>
Gender:
<Select name="gender" ><br>
<option>SELECT</option>
<option>Male</option>
<option>Female</option>
</select><br><br>
Age:
<input name="age" type="text"> yrs.<br><br>
Weight:
<input name="weight" type="text">kgs.<br><br>
Height:
<input name="height" type="text">cm.<br><br>
<br>
Page No:117

<input type="Submit" value="Calculate">


</h2>
<?php
$age=$_POST['age'];
$weight=$_POST['weight'];
$height = $_POST['height'];
$calories="0.0215183";
$gender=$_POST['gender'];
switch ($gender)
{
case 'Female':
$gender= 655 + (9.6 * $weight ) + (1.8 * $height) - (4.7 * $age);
echo "<p><h2><font color=red>Your estimated daily metabolic rate is $gender</font></h2></p>";
echo "<p><h2><font color=red>This means that you need rouhgly $gender calories a day to maintain your
current weight.</font></h2></p>";
break;
case 'Male':
$gender=66 + (13.7 *$weight) + (5 * $height) - (6.8 * $age);
echo "<p><h2><font color=red>Your estimated daily metabolic rate is $gender </font></h2></p>";
echo "<p><h2><font color=red>This means that you need rouhgly $gender calories a day to maintain your
current weight.</font></h2></p>";
break;
}?>
</form></center>
</body></html>
Page No:118

RESULT:

Thus the php program to calculate the calorie for male and female was executed
successfully.
Page No:119

EXAMPLE FOR HIDDEN FORM FIELD (SESSION TRACKING)

AIM:

To Write programs in Java using Servlets:Session tracking using hidden form fields.
DESCRIPTION:
A hidden form field is a technique used to store the session information for a particular client and
is one of an important Session Tracking Technique. In this tutorial, we will explain and show you
how to handle the hidden fields in a Servlet.

1. Introduction
Session Tracking is a technique to maintain the requests of the same user for a specific time-
period. Developers can maintain the session tracking in three ways:

 Hidden Form Field


 Cookies
 URL Rewriting
A hidden form field is a way of session tracking so that developers can save the information in the
client browser itself. For that, developers can use a hidden field for securing the fields. So at the
time of page display, no one can see these fields. When a client submits the form, the browser also
transfers these hidden value to the server with the other fields. Developers can secure the field as:
Syntax of Hidden Field
<input type="hidden" name="testHidden" value="testHiddenValue" />
In Servlet, developers can get the Hidden Form Field as:
Syntax of Request Parameter
1 String param1 = request.getParameter("testHidden");

Advantages
 Does not have to depend on the browser whether the cookie is disabled or not.
 Easier implementation.
 Hidden boxes reside in the web pages of the browser window so they do not provide a burden
to the server.

Disadvantages
 Extra form submission is required on every page which is a big overhead.
 Maintained at the server side.
 More complex than URL rewriting.
 Only textual information can be used.
 Hidden boxes do not provide data security because their data can be viewed through the
view source option.
 It increases the network traffic because the hidden data travels over the network along with
the request and response object.
Page No:120

Now, open up the Eclipse Ide and let’s see how to implement the Hidden Form field in a sample
Java-based web application.

2. Java Servlet Hidden Field Example


In this example, we are mentioning the two Hidden Form fields (i.e. name and location ) in
the index.jsp and accessing these fields into our Servlet.
index.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Servlet 3.0 Hidden Field Example</title>
<style type="text/css">
.paddingBtm {
padding-bottom: 12px;
}
</style>
</head>
<body>
<center>
<h2>Click the Submit button to check the hidden field</h2>
<form name="hiddenForm" method="post"
action="hiddenFieldServlet">
<div class="paddingBtm">
<input id="nameId" type="hidden" name="name" value="JavaCodeGeek" />
</div>
<div class="paddingBtm">
<input id="locationId" type="hidden" name="location" value="Greece" />
</div>
<div id="loginBtn">
<input id="btn" type="submit" value="Submit" />
</div>
</form>
</center>
</body>
</html>
Now in order to retrieve the hidden field value in a Servlet, we will use
the HttpServletRequest interface’s getParameter() method.
HiddenFieldServlet.java
package com.jcg.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
Page No:121

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/hiddenFieldServlet")
public class HiddenFieldServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

// This Method Is Called By The Servlet Container To Process A 'POST' Request.


public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
{ handleRequest(req, resp);
}

public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws


IOException {

resp.setContentType("text/html");

// Post Parameters From The Request


String param1 = req.getParameter("name");
String param2 = req.getParameter("location");

// Print The Response


PrintWriter out = resp.getWriter();
out.println("<html><body><center>");
out.println("<form action='index.jsp'>");
out.println("<strong>Company Name: </strong>" + param1);
out.println("<br><strong>Location: </strong>" + param2);
out.println("<br><br><i>Click on 'GoBack' button to go on JSP page</i>");
out.println("<br><input type='submit' value='GoBack'>");
out.println("</form>");
out.println("</center></body></html>");

out.close();
}
}

3. Project Deploy & Run


As we are ready for all the changes, let us compile the project and deploy the application on the
Tomcat7 server. Open your favorite browser and hit the following URL .

http://localhost:8085/JavaServletHiddenFieldEx/

The output page will be displayed.


Page No:122

RESULT:

Thus the Java program using Servlets:Session tracking using hidden form fields was
executed Successfully.

You might also like