0% found this document useful (0 votes)
120 views82 pages

Cs8661-Ip Lab Manual

Here are the steps to validate a web form using JavaScript: 1. Add an "onsubmit" event handler to the <form> tag that calls a validation function: <form onsubmit="return validateForm()"> 2. Create the validation function: function validateForm() { // validation logic return false; } 3. Get references to the form fields: var nameField = document.getElementById("name"); 4. Validate fields: - Check for empty values - Check field length - Check field format (email, number etc) 5. Prevent form submission if validation fails: if(nameField.value == "")

Uploaded by

aravindh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views82 pages

Cs8661-Ip Lab Manual

Here are the steps to validate a web form using JavaScript: 1. Add an "onsubmit" event handler to the <form> tag that calls a validation function: <form onsubmit="return validateForm()"> 2. Create the validation function: function validateForm() { // validation logic return false; } 3. Get references to the form fields: var nameField = document.getElementById("name"); 4. Validate fields: - Check for empty values - Check field length - Check field format (email, number etc) 5. Prevent form submission if validation fails: if(nameField.value == "")

Uploaded by

aravindh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 82

CS8661 : INTERNET PROGRAMMING LABORATORY

NAME :______________________________________________________

REG.NO. :______________________________________________________

YEAR /SEM :______________________________________________________


CAPE INSTITUTE OF TECHNOLOGY
BONAFIDE CERTIFICATE
NAME :

REG.NO. :

PROGRAMME :

SUBJECT CODE AND NAME :

DEPARTMENT :

SEMESTER :

Certified that this is the Bona-fide Record of work done by

Mr/Ms_________________________________________ of ________ semester

in the Department of ______________________________________ of this

College for the laboratory CS8661-INTERNET PROGRAMMING

LABORATORY during the academic year ______________.

Signature of Lecturer In-Charge Signature of HOD

Submitted for Practical Examination held on _______________

Internal Examiner External Examiner


INDEX

Ex.No Date NAME OF THE EXPERIMENT P.No Sign

Create a web page with the following using HTML


a. To embed a map in a web page
1.
b. To fix the hot spots in that map
c. Show all the related information when the hot spots are
clicked.
Create a web page with the following
a. Cascading style sheets.
b. Embedded style sheets.
2. c. Inline style sheets. Use our college information for the web
pages

3. Validate the Registration, user login, user profile and payment by


credit card pages using JavaScript.

Write programs in Java using Servlets:


i. To invoke servlets from HTML forms
4. ii. Session tracking using hidden form fields and Session
tracking for a hit count

Write programs in Java to create three-tier applications using


5. servlets for conducting on-line examination for displaying
student mark list.

Install TOMCAT web server. Convert the static web pages of


programs into dynamic web pages using servlets (or JSP) and
6. cookies. Hint: Users information (user id, password, credit card
number) would be stored in web.xml. Each user should have a
separate Shopping Cart.
Redo the previous task using JSP by converting the static web
pages into dynamic web pages. Create a database with user
7.
information and books information. The books catalogue should
be dynamically loaded from the database.

Create and save an XML document at the server, which contains


users Information. Write a Program, which takes user Id as an
8. input and returns the User details by taking the user information
from the XML document.

9. i) Validate the form using PHP regular expression


ii) PHP stores a form data into database

Write a web service for finding what people think by asking 500
people‘s opinion for any
10. consumer product.
Ex. No: 1 DATE:

IMAGE MAPPING
AIM:
To write a map and fix the hotspots to show the information of
it in a web page.

ALGORITHM:
1. Start the program.
2. Get the india map image and link it to the package.
<img src="flag.jpg">
<img align="right" src = "India Map.gif" usemap="#india">
3. Fix the hotspots in that image.
4. Map the reference of the hotspots in the image.
<area shape="circle" coords="274,745,20" href="tn.html">
5. Mention the derived link.
6. Click the link to get the desired image.
7. Stop the program.
SOURCE CODE:
Main.html
<html>
<head>
<BODY bgcolor="#gop6876cgdt5564ss">
<img src ="indiamap.jpeg" usemap="indiamap" />
<map name=indiamap>
<AREA SHAPE="rect" COORDS="190,477,251,562" HREF="tamilnadu.html"
target="tamilnadu.html" >
<AREA SHAPE="rect" COORDS="158,477,195,564" HREF="kerala.html"
target="kerala.html" >
<AREA SHAPE="rect" COORDS="217,378,238,472,350,361" HREF="andhra.html"
target="andhra.html" >
<AREA SHAPE="rect" COORDS="160,474,212,401,189,436" HREF="karnataka.html"
target="karnataka.html" >
<AREA SHAPE="rect" COORDS="137,382,219,311,129,331" HREF="maharashtra.html"
target="maharashtra.html" >
<AREA SHAPE="rect" COORDS="392,319,334,304,309,362," HREF="orissa.html"
target="orissa.html" >
<AREA SHAPE="rect" COORDS="232,244,238,306,168,283" HREF="madhayapradesh.html"
target="madhayapradesh.html" >
</map>
</head>
</html>
Tamiladu.html
<html>
<head>
<body bgcolor="#fggbhjgdhg"/>
<center><h2>it is a tamilnadu,here maximum tamilan living and capital of tamilnadu is
</h2><h1>chennai<h1></center>
</head>
</html>
Kerala.html
<html>
<head>
<body bgcolor="#7674dshddf"/>
<center>it is a kerala,here maximum malaiyalees living and capital of kerala is
<h1>Thiruvananthapuram</h1></center>
</head>
</html>
Karataka.html
<html>
<head>
<body bgcolor="#7674dshddf"/>
<center>it is a karnataka,here maximum kannadam living and capital of karnataka is
<h1>Bangalore</h1></center>
</head>
</html>
Madhyapradesh.html
<html>
<head>
<body bgcolor="blue"/>
<center>it is a madhyapradesh,here maximum maratiyam living and capital of madhyapradesh
is <h1>BHOPAL</h1></center>
</head>
</html>
Maharastra.html
<html>
<head>
<body bgcolor="blue"/>
<center>it is a maharashtra,here maximum maratiyam living and capital of maharashtra is
<h1>Mumbai</h1></center>
</head>
</html>
Orissa.html
<html>
<head>
<body bgcolor="blue"/>
<center><h2>it is a orissa,here maximum oreya living and capital of orissa is</h2>
<h1>Bhubaneswar</h1></center></head></html>

Output:
RESULT:
Thus the web page is created and the image is embedded with hot spot and the
linking ages successfully, and the output is verified.
Ex. No: 2 DATE:
STYLE SHEET
AIM:
To write a webpage that displays college information using various style sheet.

ALGORITHM:
1. Start the program.
2. Create a web page with framesets consisting two frames.
3. In the first frame include the links.
4. In the second frameset display the webpage of the link.
5. Create a external style sheets.
6. Create a inline and internal style and make a link to the external style sheet.
7. Stop the program.

SOURCE CODE:
<html>
<head>
<title>Cascading Style Sheets</title>
</head>
<body alink="blue" vlink="brown">
<h1><u><b><font face="Monotype corsiva" color="red">
Different types of Cascading Style Sheets</font>
</b></u></h1>
<br />
<font face="Arial"size="6">
<a href ="inline.html" style="text-decoration :none;"> 1. Inline Style Sheet</a><br />
<a href ="embedded.html" style="text-decoration :none;"> 2. Embeded Style
Sheet</a><br />
<a href ="external.html" style="text-decoration :none;"> 3. External Style
Sheet</a><br />
<a href ="import.html" style="text-decoration :none;"> 4. Imported Style
Sheet</a><br /></font>
</body>
</html>

Inline.html
<html>
<head>
<title>Inline Style Sheet</title>
</head>
<body>
<ol class="decimal">
<h1 style="font-family :Monotype Corsiva ;background-color:antiquewhite ;"><li>
Inline Style Sheet</li></h1>
<h3>
<p style="text-indent :30pt;color:blue;font-family :arial;">
Inine Style is the style attached to one specific element.
The style is specified directly in the start tag as a value of the style attribute well apply
exclusively to this specific element occurrence.
</p></h3>
</ol>
</body>
</html>
Embedded.html
<html>
<head>
<title>Embeded Style Sheet</title>
<style type="text/css">
ol{list-style-type:decimal}
h1{text-align: left; background:antiquewhite;font-family:monotype corsiva;color:red}
h3{text-align: right; font-family:arial;color:blue}
</style>
</head>
<body>
<ol class="lroman"><h1>
<li>Embedded style sheet</li></h1>
<br />
Embedded style is the style attached to one specific document.
The information is specified as a content of the style element
inside the head element and wil apply to the entire documents.
</h3></ol>
</body>
</html>
External.html
<html>
<head>
<title>External Style Sheet</title>
<link rel=Stylesheet href="style1.css" type="text/css" />
</head>
<body>
<h1>1. External Style Sheet</h1><br />
<h3>
An external style sheet is a template documents/files
containing style info which can be linked with any
number
of the documents. This is a very convenient way of formating
the entire site as well as restyling it by editing just one file</h3>
</body>
</html>
Import.html
<html>
<head><title>Imported Style Sheet</title>
<link rel= stylesheet href="style2.css" type="text/css">
</head>
<body>
<h1>1. Imported Style Sheet</h1>
<h3> Imported style sheet is a shet that can be imported to another sheet.
This alignes exacting one main sheet containing declarations that apply to
the whle site and partial sheets containing declarations that apply to
specific elements.</h3>
</body>
</html>

Output:
www.studentsfocus.com
RESULT:
Thus the web page is created using all tyes of cascading style sheets successfully and the
output is also verified.
EX. No: 3 DATE:
WEB FORM VALIDATION

AIM:
Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
ALGORITHM:
1.The form will include one text field called "Your Name", and a submit button. 2.Validation
script will ensure that the user enters their name before the form is sent to the server.
3. Open this page to see it in action.
4. Try pressing the Send Details button without filling anything in the "Your Name"
field. 5.You might like to open the source code for this form in a separate window
6. The page consists of a JavaScript function called validate_form() that performs the
form validation, followed by the form itself.
PROCEDURE:
Home page
Main.html:
<html>
<head>
<title>Amazon</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post" action="login.html" target=_blank >
<h4>for books</h4>
<input type="submit" value="click here">
</form>
</center>
</body>
</html>
Registration and user Login
Login.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="userpro.html" >
<input type="submit" value="register" >
&nbsp;&nbsp;
<input type="reset" value="reset"></form></td>
</tr></table></body></html>
User profile page Userpro.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>male &nbsp;&nbsp;
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset" value="reset"></td>
</tr>
</form>
</body>
</html>
Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql </td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>
Shopping cart Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select >
<optgroup label="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" id="q">
</td></tr>
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
<body>
</html>
Payment by credit card Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="cyan">
<center><h1>Payment By Credit Card</h1></center>
<form method=post action="ordrconform.html">
<br><br><br><br><br>
<table align="center">
<tr> <td>
<h4>Total Amount</h4></td>
<td><input type="text">
</td> </tr>
<tr>
<td><h4>Credit Card Number</td>
<td><input type="text"></td>
</tr> <tr> <td> </td>
<td><input type="submit" value=OK>
</td> </tr>
</table>
</form></body>
</html>
Order Conformation Ordrconform.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>
OUTPUT:
RESULT:
Thus the program has been written for creating the web page for validating the
informations.
Ex. No: 4A DATE:
INVOKING SERVLET FROM HTML FORMS
AIM:
To write a java program for invoking servlet from HTML form.

ALGORITHM:
1. Start the program.
2. Create the form as ResponseDemoServlet with
textfield,submit Button and reset button.
3. The class ResponseDemoServlet implements the interface servlet.
4. Create the out object for the PrintWriter class and call the method Getwriter
as response.getwriter.
5. Display the server port, server name, protocol, character encoding, content length.
6. Create the class as enumeration with parameters as object.
7. Stop the program.
SOURCE CODE:
Client Page:
<HTML>
<HEAD>
<TITLE>Sending a request</TITLE>
</HEAD>
<BODY>
<FORM ACTION= ResponseDemoServlet METHOD="POST">
<BR><BR>
Author: <INPUT TYPE="TEXT" NAME="Author">
<INPUT TYPE="SUBMIT" NAME="Submit">
<INPUT TYPE="RESET" VALUE="Reset">
</FORM>
</BODY>
</HTML>
Server Page:
importjavax.servlet.*;
importjava.io.PrintWriter;
importjava.io.IOException;
importjava.util.Enumeration;
public class ResponseDemoServlet implements Servlet {
public void init(ServletConfigconfig) throws ServletException {
} public void destroy() { }
public void service(ServletRequest request, ServletResponse
response) throwsServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>");
out.println("ServletResponse");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<B>Demonstrating the ServletResponse
object</B>"); out.println("<BR>");
out.println("<BR>Server Port: " + request.getServerPort());
out.println("<BR>Server Name: " + request.getServerName());
out.println("<BR>Protocol: " + request.getProtocol());
out.println("<BR>Character Encoding: " + request.getCharacterEncoding());
out.println("<BR>Content Type: " + request.getContentType());
out.println("<BR>Content Length: " + request.getContentLength());
out.println("<BR>Remote Address: " + request.getRemoteAddr());
out.println("<BR>Remote Host: " + request.getRemoteHost());
out.println("<BR>Scheme: " + request.getScheme());
Enumeration parameters =
request.getParameterNames(); while
(parameters.hasMoreElements()) {
String parameterName = (String)
parameters.nextElement(); out.println("<br>Parameter
Name: " + parameterName); out.println("<br>Parameter
Value: " + request.getParameter(parameterName));
}
Enumeration attributes = request.getAttributeNames();
while (attributes.hasMoreElements()) {
String attribute = (String) attributes.nextElement();
out.println("<BR>Attribute name: " + attribute);
out.println("<BR>Attribute value: " + request.getAttribute(attribute));
}
out.println("</BODY>");
out.println("</HTML>");
}
public String getServletInfo() {
return null;
}
publicServletConfiggetServletConfig() {
return null;
}
}
OUTPUT:

RESULT:
Thus the program for invoking servlet from HTML form was executed and the output
was verified.
Ex. No 4B DATE:
SESSION TRACKING USING HIDDEN FORM FIELDS

AIM:

To write a java servlet program for session tracking using hidden form fields.

ALGORITHM:
Step 1: Import all the necessary packages.
Step 2: Declare a class FirstServlet1 that extends HttpServlet.
Step 3: In hidden form field a hidden (invisible) textfield is used for maintaining the state of an user.
<input type='hidden' name='uname' value=” “>)
Step 4: We are storing the name of the user in a hidden textfield and getting that value from
another servlet. Step 5: After entering the name from the HTML page, it goes to the first servlet.
First Servlet gets the name and sends as an invisible text field to the servlet2.
Step 6: Second servlet accepts the hidden text field and constructs the invisible text.

PROGRAM:

FirstServlet1.java
import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet1 extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response){ try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String
n=request.getParameter("userName");
out.print("Welcome "+n);
out.print("<form action='http://localhost:8080/secserv/SecondServlet1' method
='get'>"); out.print("<input type='hidden' name='uname' value='"+n+"'>");
out.print("<input type='submit'
value='go'>"); out.print("</form>");
out.close();
}catch(Exception e)
{
System.out.println(e);
}}
}
Web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>FirstServlet1</servlet-name>
<servlet-class>FirstServlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet1</servlet-name>
<url-pattern>/FirstServlet1</url-pattern>
</servlet-mapping>
</web-app>
SecondServlet
1.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String
n=request.getParameter("uname");
out.print("Hello "+n);
out.close();
}catch(Exception e){System.out.println(e);}
}
}
Web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"
metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description> Welcome to Tomcat
</description>
<servlet>
<servlet-name>SecondServlet1</servlet-name>
<servlet-class>SecondServlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SecondServlet1</servlet-name>
<url-pattern>/SecondServlet1</url-pattern>
</servlet-mapping>
</web-app>
Hidden Field.html
<html>
<head><title>Hidden Field</title></head>
<body>
<form action="http://localhost:8080/firstserv/FirstServlet1"
method="get"> Name:<input type="text"
name="userName"/><br/>
<input type="submit" value="go"/>
</form>
</body>
</html>

SAMPLE OUTPUT:

Hidden Field.html

First Servlet
Second servlet

RESULT:
Thus the java servlet program for session tracking using hidden form fields was
executed successfully and output is verified.
EX.NO:5 DATE:
THREE TIER ARCHITECTURE USING SERVLETS
AIM:

To write a java servlet program to conduct online examination and to display student mark list
available in a database which has been stored in a database server.

ALGORITHM:
Client:
Step 1: In online.html on the client side declare the questions for online exam in which True/False
options are displayed that you like to transfer to the server using html form and input type tags.
Step 2: create a submit button and close all the included tags. Servlet:
Step 1: Import all necessary packages Step 2: Define a class that extends servlet
Step 3: In the do Post() method, do the following:
i) Set the content type of the response to "text/html" by using setContentType
ii) Create a writer to the response
iii)Get a parameter from the
request
iv) If its value is equal to right answer then add 5 to mark variable
v) Similarly repeat step for all parameters
vi) Display the result in an html format using response.getwriter( ).
PROGRAM:
online.html

<html>
<head>
<title> Database test</title>
</head>
<body>
<center>
<form action="http://localhost:8080/exam/exam" method=POST>
<div align="left"><br>
<b>seat number:</b> <input type="text" name="Seat_no">
<div align="right"><br>
<b>Name:</b> <input type="text" name="Name" size="50"><br>
</div>
<br>
<br>
<b>1.Is JAVA a platform independency</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<b>2.ASP .NET is a client side programming</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<b>3.MATHEMATICS is the backbone of engineering</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<b>4.You are working in IBM machines</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<b>5.C++ is a fully OOP's language</b><br/>
<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>

Exam.java:

import java.sql.*; import java.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*;
public class exam extends HttpServlet
{
String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5; int Total=0;

Connection connect; Statement stmt =null; ResultSet rs=null;


public void doPost(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
try
{
String url="jdbc:odbc:StudentDB2"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connect=DriverManager.getConnection(url," "," "); message="Connection Successful";
}
catch(ClassNotFoundException cnfex)
{
cnfex.printStackTrace();
}
catch(SQLException sqlex)
{
sqlex.printStackTrace();
}
catch(Exception excp)
{
excp.printStackTrace();
}
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"))
Total+=2; if(ans2.equals("False")) Total+=2; if(ans3.equals("True")) Total+=2; if(ans4.equals("True"))
Total+=2; if(ans5.equals("False")) Total+=2;
Try

{
Statement stmt=connect.createStatement();
String query="INSERT into StudentTable VALUES ("+Seat_no+",'"+Name+"',"+Total+")";
//*****"+"Seat_no,Name,Marks"+")"+" VALUES(" int result=stmt.executeUpdate(query);

stmt.close();
}
catch(SQLException ex)
{
}
response.setContentType("text/html"); PrintWriter out=response.getWriter(); out.println("<html>");
out.println("<body bgcolor=yellow>"); out.println("<h1>"+message+"</h1>\n"); out.println("<h3>DataBase
Updated"); out.println("<br><br>");
out.println("<b>"+"The Student Database is as follows"); out.println("<table border=5>");
try
{
Statement stmt=connect.createStatement(); String query="SELECT * FROM StudentTable";
rs=stmt.executeQuery(query); out.println("<th>"+"Seat_no"+"</th>"); out.println("<th>"+"Name"+"</th>");
out.println("<th>"+"Marks"+"</th>"); while(rs.next())
{
out.println("<tr>"); out.println("<td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>"); out.println("<td>"+rs.getInt(3)+"</td>"); out.println("</tr>");
}
out.println("</table>");
}
catch(SQLException ex)
{}
finally
{
try
{
if(rs!=null) rs.close(); if(stmt!=null) stmt.close(); if(connect!=null) connect.close();
}
catch(SQLException e)
{}
}

out.println("<center>"); out.println("<h1>Thanks!</h1>\n"); out.println("</center>");


out.println("</body></html>");
}}

Web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">

<display-name>Welcome to Tomcat</display-name>
<description> Welcome to Tomcat
</description>
<servlet>
<servlet-name>exam</servlet-name>
<servlet-class>exam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>exam</servlet-name>
<url-pattern>/exam</url-pattern>
</servlet-mapping>
</web-app>
Execution steps:
1. Create the database StudentDB2.mdb in which Studenttable is created. Note that we have to create an
empty database by specifying simply the field names such as Seat_no, Name and Marks.
2. Create the DSN for Student database:
Open the Control panel and double click on the Administrative Tools icon. Then double click on the
Datasources(ODBC) icon. The window appears as:

Database(Database1.mdb) –DSN CONNECTION(studentDB2)

3. Click on User DSN tab and select Microsoft Access Driver (*.mdb) and then click on the finish button. Then type the
Data Source Name as StudentDB2 and click on select button to select the database file for corresponding DSN. Click
on OK button. Now connection to the database is done using JDBC- ODBC driver.
4. Create a html program as online.html in which True/False questions are displayed.
5. Then Create a java program as Exam.java which is a servlet code for computing the total score of each student and it
displays the database contents.
6. Compile the java program by using javac exam.java. then class file will be created and place the corresponding class
file to the location c:\ "Program Files\apache-tomcat-7.0.29\webapps\exam\WEB- INF\class.
7. Then edit the web.xml file in WEB-INF for servlet name and servlet class as exam
8. Now open online.html file in a browser window the web page opens and if we click on submit button
the student information should get updated in the database by invoking a servlet.

SAMPLE OUTPUT:
RESULT:
Thus the java servlet program to conduct online examination and to display student mark list
available in a database was executed successfully and output is verified.
EX.NO:6 DATE:

SHOPPING CART

AIM:

Install TOMCAT web server. Convert the static webpages of assignments 2 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:
Steps
1. Double click the exe file and follow the steps by clicking next.
 The easiest way is to simply download and run the 32-bit/64-bit Windows Service Installer of
the latest version on Apache Tomcat. In my case the latest version of Apache Tomcat is 7 and
the download link is :
 http://mirrors.hostingromania.ro/apache.org/tomcat/tomcat-7/v7.0.26/bin/apache-tomcat-7.0.26.exe
 Run this file if you agree with the license terms and switch to the Full type of install so all the
optional components are checked in the following screen:
Figure 1-Apache Tomcat Installation - choose full install

 If you now click on Next you get the following screen:

Figure 2-Apache Tomcat installation : provide username and password


 The only think you have to do here is to fill a “User Name”, provide a “Password” for it and
eventually tick on the checkbox for “Create shortcuts for all users”. Leave everything as is. Normally
you don’t need to change anything. Click on Next.

2. Tomcat uses an environment variable named JAVA_HOME to indicate the location of the JAVA directory.
3. Additionally it uses another environment variable named CATALINA_HOME to indicate the location
of Tomcat’s Jakarta level directory.
4. In Windows XP (or equivalent) go to:
Control PanelSystemAdvancedEnvironment Variables
Click on the New button to add the following as seen with the screen grab attached:

Just these two need to be added to what ever you have already.
CATALINA_HOME c:\tomcat6\apache-tomcat-6.0.20
JAVA_HOME c:\program files\java\jdk1.6
5. Save the modifications and re-boot your computer to apply the new environment variable settings.
6. This can be tested from the command prompt (StartRun and type cmd<Enter>) by typing
ECHO followed by a space and then the variable enclosed inside a pair of % characters
(e.g. ECHO % JAVA_HOME%).
7. Starting and Stopping the server:
This is done via two batch files – startup and shutdown
They can be found in the Tomcat bin folder. It is recommended you create a shortcut for each and
place on your desktop.
Start the server by running the startup batch file – you should get a display like this:
8. Next test that the server can run a JSP page.
 In the webapps\ROOT\ folder you will find an index.jsp file.
 The ROOT folder is where the JSP pages need to live.
 Open your web browser and in offline mode type the following in the url text box:
 http://localhost:8080/index.jsp
If the following page appears then you have successfully installed Tomcat:

9. If the page does not appear then there is a problem and you should check all the steps you have
made. 10.Finally, shut down the server when not in use by simply running the shut down batch file.

Web.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Servlet 2.4 Examples</display-name>
<description>
Servlet 2.4 Examples.
</description>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-p</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
attern>order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>catalog</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>profile</url-pattern>
</servlet-mapping>
<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>
</web-app>
Main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink">
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br /><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="/tr/login.html">LOGIN</a> <a href="/tr/reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
Login.html
<html>
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/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>
Reg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br />
<form name="myform" method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br />
ADDRESS :<input type="text" name="addr" /><br />
CONTACT NUMBER :<input type="text" name="phno" /><br />
LOGINID :<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>
Profile.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/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>
Catalog.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form method="post" action="/tr/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>
Order.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br />
<form method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br />
PASSWORD :<input type="password" name="pwd"
/> 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.java
import java.sql.*;
import java.io.*;
import java.util.*;
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 bgcolor=\"pink\");
String id=req.getParamenter("id");
String pwd=req.getParameter("pwd");
try
{ Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login"; ResultSet
rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to RETRY</a>");
}
else
{
pw.println("VALID LOGIN ID<br><br>");
pw.println("<h3><ul>");
pw.println("<li><ahref=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font> </a></li><br><br>");
pw.println("<li><ahref=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
pw.println("<li><ahref=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font> </a></li><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
}
}
Reg.html
import java.sql.*;
import java.io.*;
import java.util.*;
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 bgcolor=\"pink\");
String name=req.getParamenter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id=req.getParamenter("id");
String pwd=req.getParameter("pwd");
int no=Integer.parseInt(phno);
try
{
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login"; ResultSet
rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}}
if(flag==1)
{
pw.println("SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH NEW
ID<br><br>");
pw.println("<a href=\"/tr/reg.html\">press REGISTER to RETRY</a>");
}
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insertintologin
values("+names","+addr+","+no+","+id+","+pwd+")");
pw.println("YOUR DETAILS ARE ENTERED<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
} }}
Catlog.java
import java.sql.*;
import java.io.*;
import java.util.*;
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 bgcolor=\"pink\");
String title=req.getParameter("title");
try
{
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login"; ResultSet
rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
pw.println(",div align=\"center\">");
pw.println("TITLE :"+rs.getString(1)+"<br>");
pw.println("AUTHOR :"+rs.getString(2)+"<br>");
pw.println("VERSION :"+rs.getString(3)+"<br>");
pw.println("PUBLISHER :"+rs.getString(4)+"<br>");
pw.println("COST :"+rs.getString(5)+"<br>");
pw.println("</div");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID TITLE TRY AGAIN <br><br>");
pw.println("<a href=\"/tr/catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Profile.java
import java.sql.*;
import java.io.*;
import java.util.*;
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 bgcolor=\"pink\");
String id=req.getParamenter("id");
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=DriverManager.getConnection("jdbc:oracle:thin:
@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where
id="+id+""; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME :"+rs.getString(1)+"<br>");
pw.println("ADDRESS :"+rs.getString(2)+"<br>");
pw.println("PHONE NO :"+rs.getString(3)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order.java
import java.sql.*;
import java.io.*;
import java.util.*;
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 bgcolor=\"pink\");
String id=req.getParamenter("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");
int count=Integer.parseInt(count1);
try
{
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login"; 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("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/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("AMOUNT :"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insertintodetails
values('"+id+",'"+title+"'+amount+'","'+cno+'")"');
pw.println("YOUR ORDER has taken<br>");
}
if(flag1==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}

OUTPUT:
RESULT:
Thus the java servlet program for tracking the session for each page hit count was executed
successfully and output is verified.
Ex. No: 7 DATE:
USING JSP BY CONVERTING THE STATIC WEB PAGES
INTO DYNAMIC WEB PAGES
AIM:
Redo the previous task using JSP by converting the static web pages into dynamic web pages. Create a database
with user information and books information. The books catalogue should be dynamically loaded from the database.

ALGORITHM:

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

Main.html:

<html>

<body bgcolor=”pink”>

<br><br><br><br><br><br>

<h1 align=”center”>>U>ONLINE BOOK STORAGE</u></h1><br><br><br>

<h2 align=”center”><PRE>

<b> Welcome to online book storage.

Press LOGIN if you are having id

Otherwise press REGISTRATION

</b></PRE></h2>

<br><br><pre>

<div align=”center”><a href=”/tr/login.html”>LOGIN</a>

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

</body></html>

Login.html:

<html>
<body bgcolor=”pink”><br><br><br>
<form name="myform" method="post" action=/tr1/login.jsp">
<div align="center"><pre>
LOGIN ID : <input type="passwors" name="pwd"></pre><br><br>
PASSWORD : <input type="password"
name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset"
value="clear">
</form>
</body>
</html>
Reg.html:
<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/reg.jsp">
<div align="center"><pre>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="text" name="addr"><br>
CONTACT NUMBER : <input type="text" name="phno"><br>
LOGIN ID : <input type="text" name="id"><br>
PASSWORD : <input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset"
value="clear">
</form>
</body>
</html>
Profile.html:
<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/profile.jsp">
<div align="center"><pre>
LOGIN ID : <input type="text" name="id"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset"
value="clear">
</form>
</body>
</html>
Order.html:
<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/order.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>

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


TITLE :<input type="text" name="title"><br>
NO. OF BOOKS : <input type="text"
name="no"><br> DATE : <input type="text"
name="date"><br>
CREDIT CARD NUMBER : <input type="password" name="cno"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"
value="clear" name=”button2”>
</form>
</body>
</html>
Login.jsp:
%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter(“id”);
String pwd=request.getParameter(“pwd”);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”select id,password from login where id=”+id+” and password=”+pwd+””;
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”);
out.println(“ <a href=\”/tr1/login.html\”>press LOGIN to RETRY</a>”);
}
else
{
out.println(“VALID LOGIN ID<br><br>”);
out.println(“<h3><ul>”);
out.println(“<li><ahref=\”profile.html\”><fontcolor=\”black\”>USER PROFILE</font></a></li><br><br>”);
out.println(“<li><ahref=\”catalog.html\”><fontcolor=\”black\”>BOOKS
CATALOG</font></a></li><br><br>”);
out.println(“<li><ahref=\”order.html\”><fontcolor=\”black\”>ORDER
CONFIRMATION</font></a></li><br><br>”);
out.println(“</ul>”);
}
out.println(“<body></html>”);
%>
Reg.jsp:
%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body bgcolor=\”pink\”>”);
String name=request.getParameter(“name”);
String addr=request.getParameter(“addr”);
String phno=request.getParameter(“phno”);
String id=request.getParameter(“id”);
String pwd=request.getParameter(“pwd”);
int no=Integer.parseInt(phno);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”select id from login”;
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1)))
{
flag=1;
}
}
if(flag==1)
{
out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID <br><br>”);
out.println(“<a href=\”/tr1/reg.html\”>press REGISTER to RETRY</a>”);
}
else
{
Statement stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into login values (“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”);
out.println (“YOU DETAILS ARE ENTERED <br><br>”);
out.println (“<a href =\”/tr1/login.html\”>press LOGIN to login</a>”);
} out.println (“</body></html>”);%>
Profile.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter(“id”);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.regiserDriver(d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select * from login where id=”+id+””;
ResultSet rs=stmt.executeQuery (sqlstmt);
int flag=0;
while(rs.next())
{
out.println (“<div align=\”center\”>”);
out.println (“NAME :”+rs.getString(1)+”<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(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/profile.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>
Catalog.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String title=request.getParameter (“title”);
Driver d=new oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select * from book where title=”+title+””;
ResultSet rs=stmt.executeQuery (sqlstmt);
int flag=0;
while(rs.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(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/catalog.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>
Order.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter (“id”);
String pwd=request.getParameter (“pwd”);
String title=request.getParameter (“title”);
String count1=request.getParameter (“no”);
String date=request.getParameter (“date”);
String cno=request.getParameter (“cno”);
int count=Integer.parseInt(count1);
Driver d=new oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select id, password from login”;
ResultSet rs=stmt.executeQuery (sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&& pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
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(“AMOUNT :”+amount+”<br><br><br><br>”);
Statement stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into details (“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”);
out.println (“YOU ORDER HAS TAKEN<br>”);
}
if(flag1==0)
{
out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
} out.println (“</body></html>”);%>
OUTPUT:
Result:
Thus the JSP by Converting the Static web pages into dynamic web pages was executed successfully and
verified.

Ex. No: 8 DATE:

USER INFORMATION AND INFORMATION


RETRIEVAL FROM XML

AIM:

To write a program, that takes user id as input and displays the user details by taking the user information
from the XML document.

ALGORITHM:
Step 1: Start the xml program.
Step 2: Create the 10 user information in the employee tag and insert the information about the employee in
<cse> tag.
Step 3: Then save an XML document by Info.xml which contains 10 user information..
Step 3: Next to retrieve the information by an user id use the java script tag by specifying the script language.
Step 4: Use the function readXMLData( ) in which information of 10users can be retrieved by using an
id node.
Step 5: Then validate idnode, namenode,department node,designation node by using
xmlDocumentObject.getElementsByTagName
Step 6: Next save the file as elements.html and open in the new browser window.
Step 7: Enter id number in the search prompt then the corresponding user details is displayed.
Step 8: Stop the program.
PROGRAM:
UserInformation
Info.xml
<?xml version="1.0" encoding="UTF-8"?>
<cse>

<id>2</id>
<name>Mani</name>
<department>cse</department>
<designation>AP</designation>

<id>1</id>
<name>Raj</name>
<department>cse</department>
<designation>AP</designation>
<id>3</id>
<name>jaya</name>
<department>cse</department>
<designation>AP</designation>
<id>4</id> <name>madhan</name>
<department>cse</department>
<designation>AP</designation>
<id>5</id>
<name>jaga</name>
<department>cse</department>
<designation>AP</designation>
<id>6</id>
<name>kareem</name>
<department>cse</department>
<designation>AP</designation>
<id>7</id>
<name>amala</name>
<department>cse</department>
<designation>AP</designation>
<id>8</id>
<name>geetha</name>
<department>cse</department>
<designation>AP</designation>
<id>9</id>
<name>dipthi</name>
<department>cse</department>
<designation>AP</designation>
<id>10</id>
<name>bala</name>
<department>cse</department>
<designation>AP</designation>
</cse>
InformationRetrival Elements.html
<HTML>
<HEAD>
<TITLE>Searching for Elements </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function readXMLData()
{
var xmlDocumentObject, idnode, namenode, designationnode,
departmentnode; xmlDocumentObject=new XMLHttpRequest();
xmlDocumentObject.open("GET","info.xml",false);
xmlDocumentObject.send();
xmlDocumentObject=xmlDocumentObject.responseXML;
idnode = xmlDocumentObject.getElementsByTagName("id");
departmentnode =
xmlDocumentObject.getElementsByTagName("department"); designationnode
= xmlDocumentObject.getElementsByTagName("designation"); namenode =
xmlDocumentObject.getElementsByTagName("name");
for (i = 0; i < idnode.length; i++)
{
output=idnode[i].firstChild.nodeValue;
if (output == document.getElementById("myText").value) {
displayDIV.innerHTML = idnode[i].firstChild.nodeValue + " " + namenode[i].firstChild.nodeValue + " " +
departmentnode[i].firstChild.nodeValue + " " + designationnode[i].firstChild.nodeValue
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Searching for Elements</H1>
<input type="text" id="myText" value="">
<input type="BUTTON" VALUE="Get the last senator's name" ONCLICK="readXMLData()">
<P>
<DIV ID="displayDIV"> </DIV>
</BODY>
</HTML>
Execution Steps:
1. Create and save xml program named Info.xml which contains 10 users information.
2. Then use a html program by specifying the javascript which takes user Id as an input and returns
the User details by taking the user information from the xml document.
3. Open Elements.html in a new browser window it asks for an id number.
4. If an id number is given the corresponding user details is retrieved from the xml document.

SAMPLE OUTPUT:
Output screens for XML document
Elements.html
RESULT:
Thus the program which takes user Id as an input and returns the user details by taking the
user information from the XML document is done successfully and output was verified.
Ex. No 9 DATE:

VALIDATE THE FORM USING PHP

AIM:
To validate the form using PHP regular expression and PHP stores a form data into database.
PROCEDURE:
Step 1 – Determining the Correct SQL Insert command
When you write data to a database, you use SQL statements, specifically the INSERT
command. It is straightforward, the INSERT command inserts data into the database. When you use
phpMyAdmin, you use a GUI to manage your database, but it also shows you the MySQL
commands that it ran when performing your requested tasks. We will use this feature to our
advantge to find the correct code to use. What we will do is insert a test comment using
phpMyAdmin, and then copy the INSERT command it used.
To INSERT using phpMyAdmin
1. Log into your cPanel and click the phpMyAdmin icon.
2. In the left menu, first click your database name and then click the table to work with. If
you’re following our example, we’ll first click on “_mysite” and then “comments”.
3. In the top menu, click “Insert”
4. Type in a sample comment (refer to our screenshot below) and then click GO

5. After you have run the query, phpMyAdmin will display the insert command it used (see the
screenshot below). Copy this SQL statement to a temporary location, such as a text file on your
computer.
Step 2 – Writing the PHP code that will execute MySQL Query
Now that we have a sample query, we need to modify it and run in once a user has submitted a
comment. Below is example code that will do this. If you’re not familiar with php, any line that begins with
// is a comment. It is intended for programmers to leave comments about what their code is doing so that
either themselves or other people who work on the code have an idea as to what the code is doing. In the
example below, we’ve put in comments explaining what exactly certain peicies of code are doing:

PROGRAM:
<?
if( $_POST )
{
$con = mysql_connect("localhost","inmoti6_myuser","mypassword");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("inmoti6_mysite", $con);

$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_website = $_POST['website'];
$users_comment = $_POST['comment'];

$users_name = mysql_real_escape_string($users_name);
$users_email = mysql_real_escape_string($users_email);
$users_website = mysql_real_escape_string($users_website);
$users_comment = mysql_real_escape_string($users_comment);

$articleid = $_GET['id'];
if( ! is_numeric($articleid) )
die('invalid article id');

$query = "
INSERT INTO `inmoti6_mysite`.`comments` (`id`, `name`, `email`, `website`,
`comment`, `timestamp`, `articleid`) VALUES (NULL, '$users_name',
'$users_email', '$users_website', '$users_comment',
CURRENT_TIMESTAMP, '$articleid');";

mysql_query($query);

echo "<h2>Thank you for your Comment!</h2>";

mysql_close($con);
}
?>
Step 3 – Placing our php code in our pages
Now that we have the php code to insert the comments into the database, we need to put the code
into our pages (page1.php and page2.php). In our previous article, we showed you how to use php’s include
function to help manage blocks of code effeciently, and we will again use the include function.
1. Create a file named manage_comments.php
2. Paste in the sample code above
3.Update both page1.php and page2.php to include manage_comments.php by using <?
include("manage_comments.php"); ?> at the top of the file
RESULT:
Thus the program validate the form using PHP regular expression and PHP stores a form
data into database done successfully and output was verified.
EX.NO: 10 DATE:
IMPLEMENTING AN APPLICATION USING
THE WEB SERVICES

AIM:
To implement a application using the web services.
ALGORITHM:
1. Start the program
2. Create a root rocess for reservation
3.Create a service with focus on each
item 4.Run the program, display the result
5.Stop the program.
SOURCE CODE:
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- Solution11.16 -->
<!-- Airline Reservation System-->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Airline Reservation System</title>
<script type = "text/javascript">
<!--
var input;
var secondInput;
var element;
var secondElement;
var firstCount = 0;
var economyCount = 0;
var seats = [ ,0,0,0,0,0,0,0,0,0,0]; //allocate 10-element Array
function startArray()
{
for(var i=0; i<11; i++)
{
input = window.prompt("Please type 1 for First Class and Please type 2 for Economy.","0");
if (input == 1 || input == 2)
{
element = linearSearch(seats);
if(element==-1&&input==1)
{
document.writeln("The First Class is already fully
booked<br/>");
secondQuestion(seats);
}
else if (element ==-1 && input == 2)
{
document.writeln("The Economy Class is already fully
booked<br/>");
secondQuestion(seats);
}
else
boarding Pass(input);
}
//to terminate the program
else
{
window.status="Bye-bye!";
System.exit(0);
}
}
}
function linear Search(the Array)
{
if (input == 1)
{
for (var n=0; n<6 ; n+
+) if (the Array [n] ==
0) return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n+
+) if (the Array [n] == 0)
return n;
}
return -1;
}
function boarding Pass(the Input)
{
if (input ==1)
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the First Class<br/>");
document.writeln("Your seat number is "+ element+"<br/>");
document.writeln(" <br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the EconomyClass<br/>"); document.writeln("Your
seat
number is "+ element +"<br/>");
document.writeln(" <br/>");
seats[element]= 1;
economyCount++;
}
}
functionsecondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
second Input = window.prompt("Do you want to move to Economy Class?
(If YES, please press 1. If NO, please press 2)","0");
if ( second Input == 1)
{
input = 2;
element=linear Search(seats);
document.writeln("You have been allocated to Economy
Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3 hours<br/>"); break;
}
}
}
}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to First Class? (If YES,
please press 1. If NO, please press 2)","0");
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If
NO, please press 2)","0");
boarding Pass(input); break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3
hours<br/>"); break;
}
}}
}
}
//-->
</script>
</head>
<body onload = "startArray()"></body>
</html>
OUTPUT:

RESULT:
Thus the program is executed and verified successfully.

You might also like