0% found this document useful (0 votes)
2K views

WT Lab Manual: Overview Object Web Technologies

The document outlines a lab manual covering object web technologies, with sections introducing object-oriented programming concepts in Java, the role of OOP in GUI design using Swing, exception handling and multithreading in OOP, and network and database handling through OOP using servlets and RMI. It also lists topics to be covered in each of the 5 weeks, including designing web pages for an online book store, validation of registration fields using JavaScript, and implementing a simple client-server application.

Uploaded by

Srinu Rachuri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

WT Lab Manual: Overview Object Web Technologies

The document outlines a lab manual covering object web technologies, with sections introducing object-oriented programming concepts in Java, the role of OOP in GUI design using Swing, exception handling and multithreading in OOP, and network and database handling through OOP using servlets and RMI. It also lists topics to be covered in each of the 5 weeks, including designing web pages for an online book store, validation of registration fields using JavaScript, and implementing a simple client-server application.

Uploaded by

Srinu Rachuri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 83

WT Lab Manual

LAB OBJECTIVE

 Overview Object Web Technologies

 Basic Concept of Web Technologies

 Advance Programming

1) Introduction to object oriented programming concepts- java as an object


oriented programming language. Introduction to java application and
applets-control structures-methods-arrays.
2) Object based and objects oriented programming creating packages-using
overloaded constructors-static class variables-data abstraction and
information hiding-relation between super class objects and subclass
objects composition verses inheritance-polymorphism- dynamic method
binding abstract super classes and concrete super classes –inheriting
interface-use of inner classes and wrapper classes-String to kenizer and
String Suffer classes.
3) Role of object oriented programming in designing GUI –Graphs and
Java20overview of swing- event handling, adapter classes and layout
managers. Advance GUI components- JPopup Menus- JDesktopPane-
advance layout managers.

4) Exception handling and multithreading in object oriented programming-


When exception handling should be used-java exception handling –
exceptions and inheritance-multithreading in java-thread synchronization-
daemon threads Runnable interface- Files and streams in java
5) Network and Database handling through object oriented programming –
using JOSC –processing queries-overview of servlet –introduction to
networking –establishing a simple server and a client – introduction to
RMI – implementing the remote interface.
WEEK 1:
Design the following static web pages required for an online book store web site.

1) HOME PAGE:
The static home page must contain three frames.

Top frame: Logo and the college name and links to Home page, Login page, Registration page,
Catalogue page and Cart page (the description of these pages will be given below).

Left frame: At least four links for navigation, which will display the catalogue of respective links. For
e.g.: When you click the link “CSE” the catalogue for CSE Books should be displayed in the Right
frame.

Right frame: The pages to the links in the left frame must be loaded here. Initially this page contains
description of the web site.

HomePage.html

<html>
<head>
<title> Online Book Store</title>
<frameset rows="20%,*%" scrolling="no">
<frame name="tframe" src="Title.html">
<frameset cols=20%,80%">
<frame name="tframe" src="Links.html">
<frame name="rframe" src="Home.html">
</frameset>
</frameset>
</head>
<body>
</body>
</html>
OutPut:
2) LOGIN PAGE:

LoginPage.html

<html>
<head>
<title> Online Book Store</title>
</head>
<body bgcolor="pink">
<center>
<h1>LOGIN</h1>
<form action="account.html">
<table border="0">
<tr>
<h3><td>Username:</td>
<td><input type="text" value="" name="t1"></td></h3>
</tr>
<tr>
<h3><td>Password:</td>
<td><input type="password" name="p1"></td></h3>
</tr>

<tr>
<td></td>
<td><input type="submit" value="Sign In">
<input type="submit" value="Reset"></td>
</tr>
</table>
</form>
</center>
</body>
</html>

OutPut:
WEEK 2:

3) CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the web site in a table.
The details should contain the following:
1. Snap shot of Cover Page.
2. Author Name.
3. Publisher.
4. Price.
5. Add to cart button.

Catologue.html

<html>
<head>
<title>Online Book Store</title>
</head>
<body bgcolor="pink">
<h1>Books</h1>
<ul type="square" compact>
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>DBMS</li>
<li>UNIX</li>
<li>WT</li>
</ul>
</body>
</html>

OutPut:
4) REGISTRATION PAGE:
Create a “registration form“with the following fields
1) Name (Text field)
2) Password (password field)
3) E-mail id (text field)
4) Phone number (text field)
5) Sex (radio button)
6) Date of birth (3 select boxes)
7) Languages known (check boxes – English, Telugu, Hindi, Tamil)
8) Address (text area)

RegistrationPage.html

<html>
<head>
<title> Online Book Store</title>
</head>
<body bgcolor="pink">
<center>
<h1>REGISTRATION</h1>
<table border="3">
<tr>
<h3><td>Name:</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password"></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="radio" name="r1">Male
<input type="radio" name="r1">Female</td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Phone no:</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Address:</td>
<td> <textarea name ="string"></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Sign In">
<input type="reset" value="Reset"></td>
</tr>
</table>
</center>
</body>
</html>
OutPut:
6) PAYMENT PAGE:

PaymentPage.html

<html>
<head>
<title> Online Book Store</title>
</head>
<body bgcolor="pink">
<center>
<h1>Card Information</h1>
<table border="2">
<tr>
<h3><td>Select Card Type:</td>
<td><select name=" " size="1">
<option value="type" selected>None</opiton>
<option value="credit card">Credit
Card</opiton>
<option value="master card">Master
Card</opiton>
<option value="debit card">Debit Card</opiton>
</select>
</td>
</tr>
<tr>
<td>Enter card no:</td>
<td><input type=""></td>
</tr>
<tr>
<td>Name on card:</td>
<td><input type="text"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Sign In">
<input type="reset" value="Reset"></td>
</tr>
</table>
</center>
</body>
</html>

OutPut:
WEEK 3:
VALIDATION:
Write JavaScript to validate the following fields of the above registration page.
1. Name (Name should contains alphabets and the length should not be less than 6 characters).
2. Password (Password should not be less than 6 characters length).
3. E-mail id (should not contain any invalid and must follow the standard pattern [email protected])
4. Phone number (Phone number should contain 10 digits only).
Note: You can also validate the login page with these parameters.

RegisterValidate.html

<html>
<head>
<title> Online Book Store</title>
<script language="javascript">
<!--
function validate()
{
var uname=document.getElementById("name").value;
var pass=document.getElementById("pwd").value;
var emid=document.getElementById("eid").value;
var phno=document.getElementById("pno").value;
var date=document.getElementById("date").value;
var month=document.getElementById("month").value;
var year=document.getElementById("year").value;
var addr=document.getElementById("addr").value;
var emsg="";

var uname_re=new RegExp("^[a-zA-Z]{4,}$");


var pass_re=new RegExp("^[a-zA-Z0-9]{6,}$");
var emid_re=new RegExp("\b[a-zA-Z0-9._-]+@[a-zA-Z0-
9]+\.[a-zA-Z]{2,6}\b");
var phno_re=new RegExp("^[0-9]{10}$");
var addr_re=new RegExp("^[a-zA-Z0-9.,-/]$");
if(uname=="")
emsg+="name cant be empty\n";
else if(uname.match(uname_re)==null)
emsg+="name must contain only alphabets\n";

if(pass=="")
emsg+="password cant be empty\n";
else if(pass.match(pass_re)==null)
emsg+="error in password\n";

if(emid=="")
emsg+="email id cant be empty\n";
else if(emid.match(emid_re)==null)
emsg+="enter valid email id\n";

if(phno=="")
emsg+="phno cant be empty\n";
else if(phno.match(phno_re)==null)
emsg+="enter valid phno\n";

if(addr=="")
emsg+="address cant be empty\n";
else if(addr.match(addr_re)==null)
emsg+="enter valid address\n";

if(date=="day" || month=="month" || year=="year")


emsg+="select correct DOB";

if(emsg!="")
{
alert(emsg);
return false;
}
}
-->
</script>
</head>
<body bgcolor="pink">
<form action="success.html" onSubmit="return validate()" method="post">
<center>
<h1>REGISTRATION</h1>
<table border="0">
<tr>
<h3><td>Name:</td>
<td><input type="text" id="name"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" id="pwd"></td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="text" id="eid"></td>
</tr>
<tr>
<td>Phone no:</td>
<td><input type="text" id="pno"></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="radio" name="sex" id="sex" value="male"
checked>Male
<input type="radio" name="sex" id="sex"
value="female">Female
</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><select name="date" size="1" id="date">
<option value="day" selected>Day</opiton>
<option value="1">01</opiton>
<option value="2">02</opiton>
<option value="3">03</opiton>
<option value="4">04</opiton>
<option value="5">05</opiton>
<option value="6">06</opiton>
<option value="7">07</opiton>
<option value="8">08</opiton>
<option value="9">09</opiton>
<option value="10">10</opiton>
<option value="11">11</opiton>
<option value="12">12</opiton>
<option value="13">13</opiton>
<option value="14">14</opiton>
<option value="15">15</opiton>
<option value="16">16</opiton>
<option value="17">17</opiton>
<option value="18">18</opiton>
<option value="19">19</opiton>
<option value="20">20</opiton>
<option value="21">21</opiton>
<option value="22">22</opiton>
<option value="23">23</opiton>
<option value="24">24</opiton>
<option value="25">25</opiton>
<option value="26">26</opiton>
<option value="27">27</opiton>
<option value="28">28</opiton>
<option value="29">29</opiton>
<option value="30">30</opiton>
<option value="31">31</opiton>
</select>
<select name="month" size="1" id="month">
<option value="month" selected>Month</opiton>
<option value="1">Jan</opiton>
<option value="2">Feb</opiton>
<option value="3">Mar</opiton>
<option value="4">Apr</opiton>
<option value="5">May</opiton>
<option value="6">Jun</opiton>
<option value="7">Jul</opiton>
<option value="8">Aug</opiton>
<option value="9">Sep</opiton>
<option value="10">Oct</opiton>
<option value="11">Nov</opiton>
<option value="12">Dec</opiton>
</select>
<select name="year" size="1" id="year">
<option value="year" selected>Year</opiton>
<option value="1">1980</opiton>
<option value="2">1981</opiton>
<option value="3">1982</opiton>
<option value="4">1983</opiton>
<option value="5">1984</opiton>
<option value="6">1985</opiton>
<option value="7">1986</opiton>
<option value="8">1987</opiton>
<option value="9">1988</opiton>
<option value="10">1989</opiton>
<option value="11">1990</opiton>
<option value="12">1991</opiton>
<option value="13">1992</opiton>
<option value="14">1993</opiton>
<option value="15">1994</opiton>
<option value="16">1995</opiton>
<option value="17">1996</opiton>
<option value="18">1997</opiton>
<option value="19">1998</opiton>
<option value="20">1999</opiton>
<option value="21">2000</opiton>
<option value="22">2001</opiton>
<option value="23">2002</opiton>
<option value="24">2003</opiton>
<option value="25">2004</opiton>
</select>
</td
</tr>
<tr>
<td>Address:</td>
<td> <textarea name ="string" rows="5" cols="20"
id="addr"></textarea></td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td align="left"><input type="submit" value="Sign In"></td>
<td align="center"><input type="reset" value="Reset"></td>
</tr>
</table>
</center>
</form>
</body>
</html>

Output:
Week-4:
Design a web page using CSS (Cascading Style Sheets) which includes the following:
1) Use different font, styles:
In the style definition you define how each selector should work (font, color etc.).
Then, in the body of your pages, you refer to these selectors to activate the styles.

Ssheet1.html

<html>
<head><title>Cascading Style Sheets</title>
<style type="text/css">
h2
{
border-color:voilet;
border-style:groove;
border-width:thick;
margin-left:35%;
margin-right:35%;
color:indigo;
}
p
{
color:#23238e;
font-style:italic;
font-size:12pt;
}
b.headline
{
color:red;
font-size:22px;
font-family:corsive;
text-decoration:underline;
}
.xlink
{
cursor:crosshair;
color:brown;
}
.hlink
{
cursor:help;
color:purple;
}
</style>
</head>
<body>
<center>
<h2>Cascading Style Sheets</h2>
<b class="headline">This is heading style!</b>
<br>
<a href=".html" class="xlink"><br>CROSS LINK<br></a>
<br>
<a href=".html" class="hlink">HELP LINK</a>
<br>
<p>The sentence with no styles!!!</p>
</center>
</body>
</html>
Output:
2) Set a background image for both the page and single elements on the page.

Ssheet2.html

<html>
<head><title>Cascading Style Sheets</title>
<style type="text/css">
h2
{
border-color:voilet;
border-style:groove;
border-width:thick;
margin-left:35%;
margin-right:35%;
color:white;
background-image:url(Sunset.jpg);
}
body
{
background-image:url(Blue hills.jpg);
}
p
{
color:#23238e;
font-style:italic;
font-size:12pt;
}
b.headline
{
color:red;
font-size:22px;
font-family:corsive;
text-decoration:underline;
}
.xlink
{
cursor:crosshair;
color:brown;
}
.hlink
{
cursor:help;
color:purple;
}
</style>
</head>
<body>
<center>
<h2>Cascading Style Sheets</h2>
<b class="headline">This is heading style!</b>
<br>
<a href=".html" class="xlink"><br>CROSS LINK<br></a>
<br>
<a href=".html" class="hlink">HELP LINK</a>
<br>
<p>The sentence with no styles!!!</p>
</center>
</body>
</html>
Output:
3) Control the repetition of the image with the background-repeat property.
As background-repeat: repeat Tiles the image until the entire page is filled, just like an ordinary
background image in plain HTML.

Ssheet3.html

<html>
<head><title>Cascading Style Sheets</title>
<style type="text/css">
center
{
background-image:url(Sunset.jpg);
border-color:black;
border-width:thick;
margin-left:15%;
margin-right:15%;
}
h2
{
border-color:voilet;
border-style:groove;
border-width:thick;
margin-left:20%;
margin-right:20%;
color:white;
background-image:url(Picture1.emf);
}

body
{
background-image:url(Blue hills.jpg);
}
p
{
color:#23238e;
font-style:italic;
font-size:12pt;
}
b.headline
{
color:red;
font-size:22px;
font-family:corsive;
text-decoration:underline;
}
.xlink
{
cursor:crosshair;
color:brown;
}
.hlink
{
cursor:help;
color:purple;
}
</style>
</head>
<body>
<center>
<h2>Cascading Style Sheets</h2>
<b class="headline">This is heading style!</b>
<br>
<a href=".html" class="xlink"><br>CROSS LINK<br></a>
<br>
<a href=".html" class="hlink">HELP LINK</a>
<br>
<p>The sentence with no styles!!!</p>
</center>
</body>
</html>

Output:
4) Define styles for links as
A:link
A:visited
A:active
A:hover

5) Work with layers.

6) Add a customized cursor.

Week-5:
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.

booksinfo.xml

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="books.xsl"?>
<bookinfo>
<book isbn="9954">
<title>web technologies</title>
<author>cris bates</author>
<publisher>wintek</publisher>
<edition>2</edition>
<price>285.90</price>
</book>
<book isbn="9955">
<title>how to program www</title>
<author>dietel dietel</author>
<publisher>pearson education</publisher>
<edition>2</edition>
<price>490.90</price>
</book>
<book isbn="9956">
<title>Information security</title>
<author>wiliam stallings</author>
<publisher>pearson education</publisher>
<edition>3</edition>
<price>385.45</price>
</book>
<book isbn="9957">
<title>Network programming</title>
<author>G J Kowalski</author>
<publisher>Springer</publisher>
<edition>4</edition>
<price>530.90</price>
</book>
</bookinfo>

books.xml

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" omit-xml-declaration="no" doctype-system="h8222222"


doctype-public="h8111111"/>

<xsl:template match="/">

<html xmlns="h8333333">
<head>
<title>books information</title>
</head>
<body>
<h1> Books Information</h1>
<table border="1" bgcolor="cyan">
<thead>
<tr bgcolor="gray">
<th>ISBN</th>
<th>TITLE</th>
<th>AUTHOR</th>
<th>PUBLISHER</th>
<th>EDITION</th>
<th>PRICE</th>
</tr>
</thead>
<xsl:for-each select="bookinfo/book">
<tr>
<td bgcolor="pink"><xsl:value-of select="@isbn"/></td>
<td bgcolor="green"><xsl:value-of select="title"/></td>
<td><b><xsl:value-of select="author"/></b></td>
<td bgcolor="blue"><xsl:value-of select="publisher"/></td>
<td bgcolor="red"><xsl:value-of select="edition"/></td>
<td bgcolor="yellow"><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OutPut:
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. The color should also be
changed if we change the color in the “property window “.

colors.java

package sunw.demo.colors;
import java.awt.*;
import java.awt.event.*;

public class colors extends Canvas


{
transient private Color color;
private boolean rectangular;
public colors()
{
addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent
me)
{
change();
}});
rectangular=false;
setSize(200,100);
change();
}
public boolean getRectangular()
{
return rectangular;
}

public void setRectangular(boolean flag)


{

this.rectangular=flag;
repaint();
}

public void change()


{
color=randomColor();
repaint();
}

private Color randomColor()


{
int r=(int)(255*Math.random());
int g=(int)(255*Math.random());
int b=(int)(255*Math.random());
return new Color(r,g,b);
}

public void paint(Graphics g)


{
Dimension d=getSize();
int h=d.height;
int w=d.width;
g.setColor(color);
if(rectangular)
{
g.fillRect(0,0,w-1,h-1);
}
else
{
g.fillOval(0,0,w-1,h-1);
}
}
}
colors.txt (manifest file)

Java-Bean: True
Name: sunw/demo/colors/colors.class

Output:
Week-7:
1) Install TOMCAT web server and APACHE. While installation assign port number 4040 to
TOMCAT and 8080 to APACHE. 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.

a) Installation of Apache Tomcat 6.0

1) Download the backup program of Apache Tomcat 6.0 from Apache website. Double click on it
to start the installation.

2) Then it will display some description about the installation. Click next to continue.
3) Then it will display the list of components to be installed. Don’t change anything click next to
continue.
4) Then it will display the installation directory. Click next to continue.
5) Enter the port number as 8080 and give proper username and password. Click next to continue.

6) Java Virtual Machine will be automatically detected by the Installer, once you have installed the
JDK software prior to the installation of this web server software.
7) Then the installer finishes its installation. Click on finish to complete the installation.
b) Path setting for servlet-api.jar

1) Right click on my computer then select properties.

2) Then under Advanced tab select Environment variables.


3) click on new then enter Variable name as classpath and enter Variable value as the following.

C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;.;

4) Click on OK to complete the Settings.

c) Testing the Tomcat Web Server.


1) Click on StartMenu -> Programs -> Apache Tomcat 6.0 -> Configure Tomcat.
2) Click on start to start the Tomcat service.
3) Then open the Web browser and enter the following in the address to open tomcat homepage.

http://localhost:8080
4) Then click on Tomcat Manager and provide the username and password to get into the
application managers page.

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 id’s 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 “.
Use init-parameters to do this. Store the user-names and passwords in the webinf.xml and access them
in the servlet by using the getInitParameters() method.
User Authentication Using Cookies:
Login.html

<html>
<head>
<title>login.html</title
</head>

<body bgcolor="pink">
<center>
<h1>Cookies Example</h1>
<form action="/Week8Cookies/log">
<table>
<tr>
<td><b>userid:</b></td><td><input type="text" name="username"></td>
</tr>
<tr>
<tr>
<td><b>password:</b></td><td><input type="text" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"><input type="reset"
value="Reset"></td>
</tr>
</table>
</form>
</center>
</body>
</html>

AddUsers.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddUsers extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

Cookie user1 = new Cookie("John","John123");


Cookie user2 = new Cookie("Johnson","Johnson123");
Cookie user3 = new Cookie("Rahul","Rahul123");
Cookie user4 = new Cookie("Rohit","Rohit123");
Cookie user5 = new Cookie("Raj","Raj123123");

response.addCookie(user1);
response.addCookie(user2);
response.addCookie(user3);
response.addCookie(user4);
response.addCookie(user5);
out.println("<html><body bgcolor=pink>");
out.println("<center><h1>Cookies added
Successfully</h1><center></body></html>");
out.close();
}
}

LoginForm.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginForm extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie cs[] = request.getCookies();
String userName = request.getParameter("username");
String password = request.getParameter("password");
boolean validUser = false;
String cuserName = null;
String cpassword = null;
for(Cookie c:cs){
cuserName = c.getName();
cpassword = c.getValue();
if(cuserName.equals(userName) && cpassword.equals(password)) {
validUser = true;
break;
}
}
if(validUser) {
out.println("<html><body bgcolor=pink>");
out.println("<h1>Login Successfull</h1>");
out.println("<b>Welcome " + cuserName+"</b></body></html>");
}
else {
out.println("<html><body bgcolor=pink>");
out.println("<b>"+userName + "is an invalid
user</b></body></html>");
}
out.close();
}
}
web.xml
<?xml version="1.0"?>
<web-app>
<servlet>
<servlet-name>AddUsersServlet</servlet-name>
<servlet-class>AddUsers</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AddUsersServlet</servlet-name>
<url-pattern>/add</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>LoginFormServlet</servlet-name>
<servlet-class>LoginForm</servlet-class>

</servlet>
<servlet-mapping>
<servlet-name>LoginFormServlet</servlet-name>
<url-pattern>/log</url-pattern>
</servlet-mapping>

</web-app>

Output Screens

1) URL : http://localhost:8085/WeekCookie/add

2) URL : http://localhost:8085/WeekCookie/login.html
3) URL: http://localhost:8085/WeekCookie/log?username=John&password=John123

User Authentication Using Initialization Parameters:


Login.html
<html>
<head>
<title>login.html</title
</head>

<body bgcolor="pink">
<center>
<h1>Cookies Example</h1>
<form action="/Week8Init/log">
<table>
<tr>
<td><b>userid:</b></td><td><input type="text" name="username"></td>
</tr>
<tr>
<tr>
<td><b>password:</b></td><td><input type="text" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"><input type="reset" value="Reset"></td>
</tr>
</table>
</form>
</center>
</body>
</html>

LoginForm.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginForm extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
Enumeration en = getInitParameterNames();
String userName = request.getParameter("username");
String password = request.getParameter("password");
String initName = null;
String initPass = null;
boolean validUser=false;
while (en.hasMoreElements()) {
initName = (String)en.nextElement();
initPass = getInitParameter(initName);
if(initName.equals(userName) && initPass.equals(password)) {
validUser = true;
break;
}
}
if(validUser) {
out.println("<html><body bgcolor=pink>");
out.println("<h1>Login Successfull</h1>");
out.println("<b>Welcome " + userName+"</b></body></html>");
}
else {
out.println("<html><body bgcolor=pink>");
out.println("<b>"+userName + "is an invalid
user</b></body></html>");
}
out.close();
}

web.html
<?xml version="1.0"?>
<web-app>
<servlet>
<servlet-name>LoginFormServlet</servlet-name>
<servlet-class>LoginForm</servlet-class>
<init-param>
<param-name>John</param-name>
<param-value>John123</param-value>
</init-param>
<init-param>
<param-name>Johnson</param-name>
<param-value>Johnson123</param-value>
</init-param>
<init-param>
<param-name>Rahul</param-name>
<param-value>Rahul123</param-value>
</init-param>
<init-param>
<param-name>Rohit</param-name>
<param-value>Rohit123</param-value>
</init-param>
<init-param>
<param-name>Raj</param-name>
<param-value>Raj123</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>LoginFormServlet</servlet-name>
<url-pattern>/log</url-pattern>
</servlet-mapping>
</web-app>

OutPut:

URL : http://localhost:8085/Week8Init/Login.html
URL : http://localhost:8085/Week8Init/log?username=Rohit&password=Rohit123

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).

a) Installation of Oracle 10 XE
Step 1: Double click on the backup file to start the installation process.
Installer will starts and shows some progress status.
Step 2: On welcome window click on Next contine.

Step 3: Accept the license agreement and click on Next to continue.


Step 4: Choose destination folder to install the oracle and click Next to continue.

Step 5: Provide the password as ‘manager’ and click Next to continue.


(For login username is ‘system’ by default and the password is same as you provide here)

Step 6: Then installer will show the summary of the installation. Click Install to
continue with installation.
Step 7: Here again the installer shows the progress status.

Step 8: Finally installer will show the completion message. Click Finish to complete
the installation.
Creation of DSN (Important).

Step 1: Go to control panel switch to Classic View.

Step 2: There select Administrative tools.


Step 3: Then select Data Sources (ODBC).

Step 4: In ODBC Data Source Administrative Window, click on Add to add a new
DSN (Data Source Name).
Step 5: In Create New Data Source window select “Microsoft ODBC for Oracle”
and then click on finish to continue.

Step 6: In Microsoft ODBC for Oracle Setup window provide the following details.
Data Source Name: mydsn (any user defined name).
Description:
Username: scott
Server:
Click on ok to continue.
Step 7: Finally your DSN will be listed along with already existed once. Click on ok to
complete the process now this DSN can be used in the programs when ever you want
connectivity with the oracle database.
Testing the connectivity.
A Sample Program to establish connection with database.
Output:

b) JDBC User authentication program.

Home.html

<html>
<head><title>Home Page</title>
</head>
<body bgcolor="pink">
<center>
<h1>WELCOME TO ONLINE BOOK STORE</h1>
<h5>Click Here for <a href="Login.html">LOGIN.</a></h5>
<h5>Click Here for <a href="Register.html">REGISTER.</a></h5>
</center>
</body>
</html>

Login.html

<html>
<head>
<title>login.html</title
</head>

<body bgcolor="pink">
<center>
<h1>LOGIN PAGE</h1>
<form method="post" action="/Week9UserAuthen/log">
<table>
<tr>
<td><b>userid:</b></td><td><input type="text" name="uname"></td>
</tr>
<tr>
<td><b>password:</b></td><td><input type="password" name="pwd"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"><input type="reset"
value="Reset"></td>
</tr>
</table>
</form>
<h5>Don't Have a Login ID Click here to <a
href="Register.html">REGISTER.</a></h5>
<h5>Click here to go <a href="Home.html">HOME.</a></h5>
</center>
</body>
</html>

Register.html
<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor="pink">
<center>
<h1>REGISTRATION PAGE</h1>
<form method="post" action="/Week9UserAuthen/reg">
<table border="3">
<tr>
<td>Name:</td>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="radio" name="sex" value="Male">Male
<input type="radio" name="sex"
value="Female">Female</td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Phone no:</td>
<td><input type="text" name="phno"></td>
</tr>
<tr>
<td>Address:</td>
<td> <textarea rows="4" cols="8"
name="addr"></textarea></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Sign In">
<input type="reset" value="Reset"></td>
</tr>
</table>
</form>
<h5>Already have a Login ID Click here to <a
href="Login.html">LOGIN.</a></h5>
<h5>Click here to go <a href="Home.html">HOME.</a></h5>
</center>
</body>
</html>

LoginServlet.java

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

public class LoginServlet extends HttpServlet{


public void doPost(HttpServletRequest hreq, HttpServletResponse hres)
throws ServletException, IOException
{
hres.setContentType("text/html");
PrintWriter out=hres.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
String funame=hreq.getParameter("uname");
String fpwd=hreq.getParameter("pwd");
Statement stmt=con.createStatement();
String sql="select * from customer where uname='"+funame+"' and pass='"+fpwd+"'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
out.println("<h2>Welcome "+funame+"</h2>");
else
out.println("<h2>"+funame+" Not Authorized</h2>");
con.close();
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

RegisterServlet.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RegisterServlet extends HttpServlet {
public void doPost(HttpServletRequest hreq, HttpServletResponse hres)
throws ServletException, IOException
{
hres.setContentType("text/html");
PrintWriter out=hres.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
if(con!=null)
out.println("Connection ready.....");
else
out.println("Connection not ready.....");
String funame=hreq.getParameter("uname");
String fpwd=hreq.getParameter("pwd");
String fsex=hreq.getParameter("sex");
String femail=hreq.getParameter("email");
String fphno=hreq.getParameter("phno");
String faddr=hreq.getParameter("addr");
PreparedStatement ps=con.prepareStatement("insert into
customer(uname,pass,sex,email,phno,addr) values(?,?,?,?,?,?)");
ps.setString(1,funame);
ps.setString(2,fpwd);
ps.setString(3,fsex);
ps.setString(4,femail);
ps.setString(5,fphno);
ps.setString(6,faddr);
int i=ps.executeUpdate();
I if(i==1)
out.println("<h2>Registration Successfull....</h2>");
else
out.println("Registration Failed....");
con.close();
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

web.xml

<?xml version="1.0”?>
<web-app>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/log</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/reg</url-pattern>
</servlet-mapping>
</web-app>

Output:
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 (similar to week8 instead of cookies).

Home.html
<html>
<head><title>Home Page</title>
</head>
<body bgcolor="pink">
<center>
<h1>WELCOME TO ONLINE BOOK STORE</h1>
<h5>Click Here for <a href="Login.html">LOGIN.</a></h5>
<h5>Click Here for <a href="Register.html">REGISTER.</a></h5>
</center>
</body>
</html>

Login.html

<html>
<head>
<title>login.html</title
</head>
<body bgcolor="pink">
<center>
<h1>LOGIN PAGE</h1>
<form method="post" action="/Week10UserAuthen/log">
<table>
<tr>
<td><b>userid:</b></td><td><input type="text"
name="uname"></td>
</tr>
<tr>
<td><b>password:</b></td><td><input type="password"
name="pwd"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"><input type="reset"
value="Reset"></td>
</tr>
</table>
</form>
<h5>Don't Have a Login ID Click here to <a
href="Register.html">REGISTER.</a></h5>
<h5>Click here to go <a href="Home.html">HOME.</a></h5>
</center>
</body>
</html>

Register.html

<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor="pink">
<center>
<h1>REGISTRATION PAGE</h1>
<form method="post" action="/Week10UserAuthen/reg">
<table border="3">
<tr>
<td>Name:</td>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="radio" name="sex" value="Male">Male
<input type="radio" name="sex" value="Female">Female</td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Phone no:</td>
<td><input type="text" name="phno"></td>
</tr>
<tr>
<td>Address:</td>
<td> <textarea rows="4" cols="8" name="addr"></textarea></td>
</tr>
<tr>
<td></td><td><input type="submit" value="Sign In">
<input type="reset" value="Reset"></td>
</tr>
</table>
</form>
<h5>Already have a Login ID Click here to <a
href="Login.html">LOGIN.</a></h5>
<h5>Click here to go <a href="Home.html">HOME.</a></h5>
</center>
</body>
</html>

Login.jsp

<%@ page import="java.sql.*" %>


<%@ page import="java.io.*" %>
<%!
String funame,fpwd,query;
Connection con;
Statement st;
ResultSet rs;
%>
<%
funame=request.getParameter("uname");
fpwd=request.getParameter("pwd");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:mydsn","scott","tiger");
st=con.createStatement();
query="select * from customer where uname='"+funame+"' and
pass='"+fpwd+"'";
rs=st.executeQuery(query);
if(rs.next())
{
%>
<h1>WelCome <%=funame%></h1>
<%
}
else
{
%>
<h1><%=funame%> Invalid User</h1>
<%
}
} catch(Exception e)
{
out.println(e);
}%>

Register.jsp

<%@ page import="java.sql.*" %>


<%@ page import="java.io.*" %>
<%!
String funame,fpwd,fsex,femail,fphno,faddr,query;
Connection con;
PreparedStatement pst;
ResultSet rs;
%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
if(con!=null)
out.println("Connection ready.....");
else
out.println("Connection not ready.....");
funame=request.getParameter("uname");
fpwd=request.getParameter("pwd");
fsex=request.getParameter("sex");
femail=request.getParameter("email");
fphno=request.getParameter("phno");
faddr=request.getParameter("addr");
pst=con.prepareStatement("insert into
customer(uname,pass,sex,email,phno,addr)values(?,?,?,?,?,?)");
pst.setString(1,funame);
pst.setString(2,fpwd);
pst.setString(3,fsex);
pst.setString(4,femail);
pst.setString(5,fphno);
pst.setString(6,faddr);
int i=pst.executeUpdate();
if(i==1)
{
%>
<h2>Registration Successfull....</h2>
<%
}
else
{ %>
<h2>Registration Failed....</h2>
<%
}
con.close();
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
OutPut:
Week-11:
Create tables in the database which contain the details of items (books in our case like Book name ,
Price, Quantity, Amount )) of each category. Modify your catalogue page (week 2) in such a way that
you should connect to the database and extract data from the tables and display them in the catalogue
page using JDBC.

Database:
1) Create the following table.
SQL> create table bookinfo(title varchar2(20),author varchar2(30), edition
varch
ar2(5),price varchar2(7),quant varchar2(5),amount varchar2(7));

2) Insert the following records.


SQL> insert into bookinfo values('Java','Complete reference','5rd','120.00','27'
,'1000');
1 row created.

SQL> insert into bookinfo values('Java Server Pages','PSW','3rd','174.00','29','


9000');
1 row created.

SQL> commit;
Commit complete.

catalogue.jsp

<%@ page import="java.sql.*" %>


<%@ page import="java.io.*" %>
<%!
String btitle,bauthor,bedition,bprice,bquantitiy,bamount,query;
Connection con;
Statement st;
ResultSet rs;
%>
<% try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:mydsn","scott","tiger");
st=con.createStatement();
query="select * from bookinfo";
rs=st.executeQuery(query);
if(rs.next())
{
%>
<center>
<h1>Books Information</h1>
<table border="1">
<thead>
<tr bgcolor="gray">
<th>Title</th>
<th>Author</th>
<th>Edition</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
<th>Add to cart</th>
</tr>
</thead>
<tbody>
<tr bgcolor="yellow">
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><input type="submit" value="Add to Cart" /></td>
</tr>

<%
while(rs.next())
{
%>
<tr bgcolor="yellow">
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><input type="submit" value="Add to Cart" /></td>
</tr>
<%
}
%>
</tbody>
</table>
</center>
<%
}
else
{
%>
<h1> No data Found</h1>
<%
}
}
catch(Exception e)
{
System.out.println(e);
}%>
OUTPUT:

Week-12:
HTTP is a stateless protocol. Session is required to maintain the state. The user may add some items to
cart from the catalog page. He can check the cart page for the selected items. He may visit the catalogue
again and select some more items. Here our interest is the selected items should be added to the old cart
rather than a new cart. Multiple users can do the same thing at a time(i.e., from different systems in the
LAN using the ip-address instead of local host). This can be achieved through the use of sessions.
Every user will have his own
session which will be created after his successful login to the website. When the user logs out his
session should get invalidated (by using the method session.invalidate() ). Modify your catalogue and
cart JSP pages to achieve the above mentioned functionality using sessions.

You might also like