WT Lab Manual: Overview Object Web Technologies
WT Lab Manual: Overview Object Web Technologies
LAB OBJECTIVE
Advance Programming
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="";
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(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
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: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.*;
this.rectangular=flag;
repaint();
}
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.
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
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();
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.*;
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
<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 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 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:
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.*;
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
Register.jsp
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));
SQL> commit;
Commit complete.
catalogue.jsp
<%
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.