Record-cs8661-Internet Programming Lab Even Sem-2021
Record-cs8661-Internet Programming Lab Even Sem-2021
Record-cs8661-Internet Programming Lab Even Sem-2021
(2020-2021)
Name :
Reg No. :
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
2020- 2021 .
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
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 Header section of a document
Purpose: Specifies the text that should appear on the title bar of a browser window
Purpose: Indicates the beginning and the end of the document‟s content
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: Displays the text enclosed with these tags in bigger size
Purpose: Displays the text enclosed with these tags in smaller size
Purpose: Displays the text enclosed with these tags in specified font
Anchor tag
Purpose: HTML uses the <A> (anchor) tag to create a link to another document.
Frames
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
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
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
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
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
ALGORITHM
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
Shape
Specifies the shape of the area
Syntax
<area shape="default|rect|circle|poly">
Value Description
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")
Value Description
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
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
CSS Syntax
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
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
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;}
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
AIM
To validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
ALGORITHM
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()">
<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()">
<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()">
<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()">
<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()">
<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
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 {
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
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
});
}}
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
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
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
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:
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()" />
<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()" />
<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()" />
<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"/>
<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
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
}
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
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
AIM
To Redo the previous task using JSP by converting the static web pages of assignments 2
into dynamic web pages.
PROCEDURE
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
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
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
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
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
OUTPUT
RESULT
Thus the PHP program to stores a form data into database was coded and the output was
verified successfully.
Page No:78
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
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
@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:
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
4. Write the java script function to validate all mandatory fields on your web page.
/**********************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
{
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
RESULT:
Thus the HTML page using java script to design a webpage to validate a form
was executed successfully.
Page No:92
AIM:
To write a simple servlet program using HTTP in java.
ALGORITHM:
7. Create a folder Servlet under that create folder WEB-INF inside create a folder named classes
8. Inside WEB-INF place the web.xml file i.e. the deployment descriptor file
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">
/**************************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
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.
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.
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>
/*************************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****************************/
<html>
<body bgcolor="YELLOW">
/******************************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>
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
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
browser
6. We have to create a database in access within that create a table name users and login with
/************************** 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
/************************** 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);
}
return (false);
}
if (theForm.ed.value == "")
{
alert("Please enter your Email id");
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
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);
}
}
</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
<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
Aim
Algorithm
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
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
RESULT:
Thus the php program to calculate the calorie for male and female was executed
successfully.
Page No:119
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:
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.
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 {
resp.setContentType("text/html");
out.close();
}
}
http://localhost:8085/JavaServletHiddenFieldEx/
RESULT:
Thus the Java program using Servlets:Session tracking using hidden form fields was
executed Successfully.