Web Technology Lab Manual
Web Technology Lab Manual
WEB TECHNOLOGIES
LAB MANUAL FOR
CSE & IT
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 1
INDEX
S. No
Contents
Page. No
Lab Objective
Guidelines to Students
4
6
Prepared By:
S. PHANI KUMAR, IT Dept.
7
9 - 74
Page 2
Advance Programming
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 3
RAM
256 MB
Hard Disk
40 GB
Mouse
Optical Mouse
Present
Software
All systems are configured in DUAL BOOT mode i.e., Students can boot from Windows
XP or Linux as per their lab requirement.
This is very useful for students because they are familiar with different Operating
Systems so that they can execute their programs in different programming
environments.
Each student has a separate login for database access
Oracle 9i client version is installed in all systems. On the server, account for each
student has been created.
This is very useful because students can save their work ( scenarios, pl/sql
programs, data related projects ,etc) in their own accounts. Each student work is safe and
secure from other students.
Latest Technologies like DOTNET and J2EE are installed in some systems.
Before submitting their final project, they can start doing mini project from 2nd year
onwards.
MASM ( Macro Assembler ) is installed in all the systems
Students can execute their assembly language programs using MASM. MASM is
very useful students because when they execute their programs they can see
contents of Processor Registers and how each instruction is being executed in the
CPU.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 4
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 5
Equipment in the lab for the use of student community. Students need to maintain a
proper decorum in the computer lab. Students must use the equipment with care. Any
damage is caused is punishable.
Students are required to carry their observation / programs book with completed exercises
while entering the lab.
Students are supposed to occupy the machines allotted to them and are not supposed to
talk or make noise in the lab. The allocation is put up on the lab notice board.
Lab can be used in free time / lunch hours by the students who need to use the systems
should take prior permission from the lab in-charge.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 6
S.No
1, 2
3, 4
Develop static pages (using only HTML) of an online Book store. The
pages should resemble: www.amazon.com
The website should consist the following pages.
Home page, Registration and user Login, User profile page, Books
catalog, Shopping cart, Payment By credit card, order confirmation.
Validate the registration, user login, user profile and payment by credit
card pages using JavaScript.
Write an XML file which will display the Book information which
includes the following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML
file.
Display the XML file as follows.
The contents should be displayed in a table. The header of the table
should be in color GREY. And the Author names column should be
displayed in one color and should be capitalized and in bold. Use your
own colors for remaining columns. Use XML schemas XSL and CSS
for the above purpose.
VISUAL BEANS:
Create a simple visual bean with a area filled with a color. The shape of
the area depends on the property shape. If it is set to true then the shape
of the area is Square and it is Circle, if it is false. The color of the area
should be changed dynamically for every mouse click.
1) Install TOMCAT web server. While installation assign port number
8080. Make sure that these ports are available i.e., no other process is
using this port.
2) Access the above developed static web pages for books web site,
using these servers by Putting the web pages developed in week-1 and
week-2 in the document root. Access the pages by using the urls :
http://localhost:8080/rama/books.html
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 7
User Authentication :
8
10
Assume four users user1, user2, user3 and user4 having the passwords
pwd1, pwd2, pwd3 And, pwd4 respectively. Write a servelet for doing
the following.
1. Create a Cookie and add these four user ids and passwords to this
Cookie.
2. Read the user id and passwords entered in the Login form (week1)
and authenticate with the values (user id and passwords ) available in the
cookies. If he is a valid user(i.e., user-name and password match) you
should welcome him by name(user-name) else you should display You
are not an authenticated user .
Install a database(Mysql or Oracle).
Create a table which should contain at least the following fields: name,
password, email-id, phone number(these should hold the data from the
registration form).
Practice 'JDBC' connectivity. Write a java program/servlet/JSP
to connect to that database and extract data from the tables and display
them. Experiment with various SQL queries. Insert the details of the
users who register with the web site, whenever a new user clicks the
submit button in the registration page (week2).
Write a JSP which does the following job:
Insert the details of the 3 or 4 users who register with the web site
(week9) by using registration form. Authenticate the user when he
submits the login form using the user name and password from the
database.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 8
WEEK- 1, 2:
AIM:
Develop static pages (using only HTML) of an online Book store. The
pages should resemble: www.amazon.com. The website should consist
the following pages.
Home page
Registration and user Login
User profile page
Books catalog
Shopping cart
Payment by credit card Order Conformation
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>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 9
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 10
<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
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female
<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>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 11
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>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 12
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>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 13
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 14
Order Conformation
Ordrconform:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 15
Main.html:
Login.html:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 16
Userpro.htm
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 17
Shooping.html:
Payment.html:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 18
Ordrconform.html:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 19
WEEK- 3, 4 :
AIM
Validate the Registration, user login, user profile and payment by
credit card pages using JavaScript.
PROCEDURE:
Home page:
Main.html:
<html>
<frameset rows="25%,*">
<frame src="top.html" name="top" scrolling ="no" frameborder ="0">
<frameset cols="25%,75%">
<frame src="left.html" name="left" scrolling ="no" frameborder ="0">
<frame src="right.html" name="right" scrolling ="auto" frameborder ="0">
</frameset>
</frameset>
</html>
Top.html:
<html>
<body bgcolor="pink">
<br><br>
<marquee><h1 align=center><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 20
Right.html:
<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press login if you are
having id otherwise press registration.
</p></b></h2>
</body> </html>
Left.html:
<html>
<body bgcolor="pink">
<h3>
<ul>
<li><a href="login.html" target="right"><font color="black">
LOGIN</font></a></li><br><br>
<li><a href="profile.html" target="right"><font color="black">
USER PROFILE</font></a></li><br><br>
<li><a href="catalog.html" target="right"><font color="black">
BOOKS CATALOG</font></a></li><br><br>
<li><a href="scart.html" target="right"><font color="black">
SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font color="black">
PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 21
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 22
<html>
<body bgcolor="pink"><br><br>
<script type="text/javascript">
function validate()
{
var flag=1;
if(document.myform.name.value==""||
document.myform.addr.value==""||
document.myform.phno.value==""||
document.myform.id.value==""||
document.myform.pwd.value=="")
{
alert("Enter all the details");
flag=0;
}
var str=document.myform.phno.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
if(!(str.length==10))
flag=0;
}
var str1=document.myform.id.value;
var x1=new RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid UserID");
}
var str1=document.myform.pwd.value;
var x1=new RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid password");
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="login.html";
}
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 23
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:<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="button" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form></body></html>
Books catalog:
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.title.value=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c"||str=="C")
{
document.myform.t1.value="C";
document.myform.t2.value=444;
}
else if(str=="jsp"||str=="JSP")
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 24
else
{
document.myform.t1.value="JSP";
document.myform.t2.value=555;
}
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" action="payment.html" target="right">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br>
</pre><br><br>
Book Title: <input type="text" name="t1" disabled>
Book Cost: <input type="text" name="t2" disabled>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
<input type="submit" value="Purchase">
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 25
Shopping cart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.title.value==""||
document.myform.no.value==""||
document.myform.cost.value=="")
{
flag=0;
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
flag=0;
}
if(flag==1)
{
else
alert("VALID INPUT");
}
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" action="scart.html" target="right">
<div align="center"><pre>
LOGIN ID
:<input type="text" name="id"><br>
TITLE
:<input type="text" name="title"><br>
NO.OF BOOKS
:<input type="text" name="no"><br>
COST OF BOOK
:<input type="text"name="cost"><br>
</pre><br><br>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 26
Page 27
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>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 28
OUTPUT:
Main.html
Login.html:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 29
Catalog.html:
Scart.html:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 30
Payment.html:
Order.html
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 31
WEEK-5.
AIM: Write an XML file which will display the Book information which includes the
following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML file.
Display the XML file as follows.
The contents should be displayed in a table. The header of the table should be in color GREY.
And the Author names column should be displayed in one color and should be capitalized and in
bold. Use your own colors for remaining columns. Use XML schemas XSL and CSS for the
above purpose.
1. Books.DTD:
<!ELEMENT details (title, author, ISBN_Number, publisher, edition, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT ISBN_Number (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
2. Th.CSS
.thb
{
background-color:gray;
}
.bg
{
background-color:red;
}
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 32
3. Books.XML:
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "books.dtd">
<book>
<details>
<title> C</title>
<author> BalaGuru Swami</author>
<ISBN_Number>2536</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>255/-</price>
</details>
<details>
<title> C++</title>
<author> BalaGuru Swami</author>
<ISBN_Number>5236</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>315/-</price>
</details>
<details>
<title> E-Commerce</title>
<author> Kalakata</author>
<ISBN_Number>8562</ISBN_Number>
<publisher>pearson</publisher>
<edition>5</edition>
<price>300/-</price>
</details>
<details>
<title> CO</title>
<author> Marris </author>
<ISBN_Number>4578</ISBN_Number>
<publisher>Dream Tech</publisher>
<edition>5</edition>
<price>270/-</price>
</details>
<details>
<title> Web Technologies</title>
<author> Kumar </author>
<ISBN_Number>5423</ISBN_Number>
<publisher>Willay</publisher>
<edition>6</edition>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 33
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 34
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 35
OUTPUT:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 36
Week-6:
VISUAL BEANS:
Create a simple visual bean with a area filled with a color. The shape of the area depends on the
property shape. If it is set to true then the shape of the area is Square and it is Circle, if it is false.
The color of the area should be changed dynamically for every mouse click.
Process:
Here are the steps that you must follow to create a new Bean:
1. Create a directory for the new Bean.
2. Create the Java source file(s).
3. Compile the source file(s).
4. Create a manifest file.
5. Generate a JAR file.
6. Start the BDK.
7. Test.
The following sections discuss each of these steps in detail.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 37
Page 38
Page 39
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 40
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 41
Week-7:
1) Install TOMCAT web server. While installation assign port number 8080. Make sure that
these ports are available i.e., no other process is using this port.
2) Access the above developed static web pages for books web site, using these servers by
Putting the web pages developed in week-1 and week-2 in the document root.
Access the pages by using the urls : http://localhost:8080/rama/books.html
1. Install the TOMCAT web server:
Step 1:
Installation of JDK:
Before beginning the process of installing Tomcat on your system, ensure first the availability of
JDK on your system program directory. Install it on your system if not already installed (because
any version of tomcat requires the Java 1.6 or higher versions) and then set the class path
(environment variable) of JDK. To set the JAVA_HOME Variable: you need to specify the
location of the java run time environment to support the Tomcat else Tomcat server can not run.
This variable contains the path of JDK installation directory.
set JAVA_HOME=C:\Program Files\Java\jdk1.6
Note: it should not contain the path up to bin folder. Here, we have taken the URL path
according to our installation convention.
For Windows OS, go through the following steps:
First, right click on the
My Computer->properties->advance->Environment
Variables->New->set the Variable name =
JAVA_HOME and variable value = C:\Program
Files\Java\jdk1.6
Now click on all the subsequent ok buttons one by one. It will set the JDK path.
Step 2:
For setting the class path variable for JDK, do like this:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 42
A Welcome screen shot appears that shows the beginning of installation process. Just click on
the 'Next' button to proceed the installation process.
Steps 4:
A screen of 'License Agreement' displays.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 43
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 44
The port number will be your choice on which you want to run the tomcat server. The port
number 8080 is the default port value for tomcat server to proceed the HTTP requests. The user
can also change the 'port number' after completing the process of installation; for this, users have
to follow the following tips.
Go to the specified location as " Tomcat 6.0 \conf \server.xml ". Within the server.xml file
choose "Connector" tag and change the port number.
Now, click on the 'Next' button to further proceed the installation process.
Step 7:
A Window of Java Virtual Machine displays on the screen
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 45
This window asks for the location of the installed Java Virtual Machine. Browse the location of
the JRE folder and click on the Install button. This will install the Apache tomcat at the specified
location.
Step 8:
A processing window of installing displays on the screen.
To get the information about installer click on the "Show details" button
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 46
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 47
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 48
PROCEDURE:
1. First install the tomcat into the system.
2. Then make a sub directory(eg., books) in the \tomcat\webapps.
3. Under books create WEB-INF directory and also place week1 programs in this books
directory only.
4. After this start tomcat by giving the following command at the instll_dir>tomcat>bin
5. Catalina.bat run
6. At the I.E(web browser) give the url as http://localhost:8080/ books /main.html
7. Port no 8080 is assigned for the tomcat.
Screen shot:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 49
Week-8:
User Authentication :
Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3
And, pwd4 respectively. Write a servelet for doing the following.
1. Create a Cookie and add these four user ids and passwords to this Cookie.
2. Read the user id and passwords entered in the Login form (week1) and authenticate
with the values (user id and passwords ) available in the cookies.
If he is a valid user(i.e., user-name and password match) you should welcome him by
name(user-name) else you should display You are not an authenticated user .
PROCEDURE:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Login.html:
<html>
<body bgcolor="pink">
<form action="show" method="get">
<center>User Name: <input type="test" name="name"><br>
Password:<input type="password" name="pass"><br>
<input type="submit" name="b1">
<input type="Button" name="b2" value="Reset">
</center>
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 50
Login.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example using servlet initialization. Here, the message
* to print and the number of times the message should be
* repeated is taken from the init parameters.
*/
public class login extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String na=request.getParameter("name");
String pa=request.getParameter("pass");
PrintWriter out = response.getWriter();
Cookie nam1=new Cookie("user1","pace");
Cookie nam2=new Cookie("user2","phani");
Cookie nam3=new Cookie("user3","cse");
Cookie nam4=new Cookie("user4","ece");
Cookie pas1=new Cookie("pwd1","college");
Cookie pas2=new Cookie("pwd2","kumar");
Cookie pas3=new Cookie("pwd3","it");
Cookie pas4=new Cookie("pwd4","eee");
int flag=0;
String nam[]={nam1.getValue(),nam2.getValue(),nam3.getValue(),nam4.getValue()};
String pas[]={pas1.getValue(),pas2.getValue(),pas3.getValue(),pas4.getValue()};
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 51
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 52
Web.xml:
<web-app>
<servlet>
<servlet-name>log </servlet-name>
<servlet-class>login </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>log </servlet-name>
<url-pattern> /show </url-pattern>
</servlet-mapping>
</web-app>
Create a directory:
Create a directory cookies, in that directory copy login.html file and create a directory a
WEB-INF. In that WEB-INF directory again create directory classes and copy web.xml file.
Compile the servlet:
Compile the servlet file then copy the class file of that servlet into the directory
C:\Program Files\Apache Software Foundation\Tomcat 6.0\cookies\WEB-INF\classes.
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 53
Login.html:
Login.java:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 54
Week-9:
Install a database(Mysql or Oracle).
Create a table which should contain at least the following fields: name, password, email-id,
phone number(these should hold the data from the registration form).
Practice 'JDBC' connectivity.
Write a java program/servlet/JSP to connect to that database and extract data from the tables and
display them. Experiment with various SQL queries. Insert the details of the users who register
with the web site, whenever a new user clicks the submit button in the registration page (week2).
Main.html:
<html>
<body>
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br/><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"/>
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 55
Profile.html
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Userinfo.html
<html>
<head>
<title>User Info Entry Form</title>
</head>
<body bgcolor="white">
<form action="userinfo1.jsp" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="userName" >
</td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="text" name="sex" >
</td>
<td>(Male or female)</td>
</tr>
<tr>
<td colspan=2><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 56
Reg.html
<html>
<body><br /><br />
<form name="myform" method="post" action="reg">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
login.java
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 57
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 58
reg.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
resp.setContentType("text/html");
pw.println("<html><body>");
String name=req.getParameter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id1=req.getParameter("id");
String pwd1=req.getParameter("pwd");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1522 :XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(4))&&pwd1.equals(rs.getString(5)))
{
flag=1;
}
}
if(flag==1)
{
pw.println("<br><br>SORRY INVALID ID ALREADY EXITS
TRY AGAIN WITH NEW ID<br><br>");
pw.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}
else
{
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login values
('"+name+"','"+addr+"','"+phno+"','"+id1+"','"+pwd1+"')");
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 59
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
Catalog.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String title=req.getParameter("title");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("TITLE
:"+rs.getString(1)+"<br>");
pw.println("AUTHOR
:"+rs.getString(2)+"<br>");
pw.println("VERSION
:"+rs.getString(3)+"<br>");
pw.println("PUBLISHER
:"+rs.getString(4)+"<br>");
pw.println("COST
:"+rs.getString(5)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID TITLE TRY AGAIN <br><br>");
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 60
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
profile.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class profile extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id='"+id+"'";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME
:"+rs.getString(1)+"<br>");
pw.println("ADDRESS :"+rs.getString(2)+"<br>");
pw.println("PHONE NO
:"+rs.getString(3)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 61
catch(Exception e)
{
resp.sendError(500,e.toString());
}
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("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(4))&&pwd.equals(rs.getString(5)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href= \" order.html \" >press HERE to RETRY</a>");
}
else
{
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 62
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 63
OUTPUT:
Main.html:
Registration:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 64
Login Page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 65
Profile page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 66
Catalog page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 67
Order page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 68
Week-10:
Write a JSP which does the following job:
Insert the details of the 3 or 4 users who register with the web site (week9) by using registration
form. Authenticate the user when he submits the login form using the user name and password
from the database.
Main.html:
<html>
<body>
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br /><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login.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()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 69
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg.jsp">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 70
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("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","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+"',"+phno+",'"+id1+"','"+pwd1+"');");
out.println("<br><br>YOUR DETAILS ARE ENTERED<br><br>");
out.println("<a href=\"login.html\">press LOGIN to login</a>");
}
out.println("</body></html>");
con.close();
%>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 71
Login.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<html>
<body>
<% String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{
out.println("<br><br>VALID LOGIN ID<br><br>");
out.println("WELCOME <br>To<br>+id);
}
con.close();
%>
</body>
</html>
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 72
OUTPUT:
Main.html:
Registration page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 73
Login page:
Prepared By:
S. PHANI KUMAR, IT Dept.
Page 74