Вы находитесь на странице: 1из 54

Gokaraju Rangaraju Institute of Engineering and Technology

Department of Computer Science and Engineering

Year/Semester : III / II

Academic year: 2018-19


WEB TECHNOLOGIES LAB

Hardware and Software required :

1. A working computer system with either Windows

2. A web browser either IE or firefox

3. Netbeans 8.1

4. A database either Mysql or Oracle

6. JDK must be installed on your system

7. BDK(Bean development kit) must be also be installed

TASK 1 and TASK 2


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 te left frame must be loaded here. Initially this page
contains description of the web site
HOME.html

<html>
<frameset rows="20%,*">
<frame name="title" src="title.html" noresize/>
<frameset cols="20%,*">
<frame name="links" src ="links.html">
<frame name="body" src ="desc.html">
</frameset>
</frameset>
<html>

TITLE.HTML
<html>
<body background="4.jpg">
<table border="0"
width="100%"
height="100%">
<tr>
<td rowspan="2"><img src="logo.jpg" width="80px" height="100px">
<th colspan="4" rowspan="1"><font size="7">ONLINE BOOK STORE
</tr>
<tr>
<td><b><a href="desc.html" target="body">Home</a>
<td><b><a href="login.html" target="body">Login</a>
<td ><b><a href="registration.html" target="body">Registration</a>
<td><b><a href="catalog.html" target="body">Catalog</a>
<td><b><a href="cart.html" target="body">Cart</a>
</tr>
</table>
</body>
</html>

LINKS.HTML

<html>
<body background="2.jpg">
<center><h2>
<a href="cse.html" target="body">CSE</a><br><br><br><br>
<a href="ece.html" target="body">ECE</a><br><br><br><br>
<a href="eee.html" target="body">EEE</a><br><br><br><br>
<a href="civil.html" target="body">CIVIL</a><br><br><br><br>
<a href="mech.html" target="body">MECHANICAL</a>
</center>
</body>
</html>

DESC.HTML
<html>
<body>
<center>
<h1><u>description of website</u></h1>
</center>
</body>
</html>

LOGIN.HTML
<html>
<body bgcolor="skyblue">
<center><h1><u>Login window</u></h1></center>
<form name="myform" method="get" action="verify.jsp">
<center>
<table border="0">
<tr>
<td>enter the user name
<td><input type="text" size="25">
</tr>
<tr>
<td>enter the password
<td><input type="password" size="25">
</tr>
<tr>
<td><input type="submit" value="login">
<td><input type="reset" value="reset">
</tr>
</table>
</center>
</form>
</body>
</html>

CSE.HTML
<html>
<body>
<center>
<h1>WELCOME TO DEPARTMENT OF CSE</h1>
</center>
</body>
</html>
CIVIL.HTML
<html>
<body>
<center>
<h1>WELCOME TO DEPARTMENT OF CIVIL</h1>
</center>
</body>
</html>
TASK2

CART.HTML
<html>
<head>
<title>cart page</title>
</head>
<body background="4.jpg">
<center>
<table border="0" cellspacing="25" >
<tr>
<th>Bookname
<th>price
<th>quantity
<th>amount
</tr>
<tr>
<td>java2
<td>Rs.250
<td>3
<td>Rs.750
</tr>
<tr>
<td>WT
<td>Rs.300
<td>2
<td>Rs.600
</tr>
</table>
</center>
</body>
</html>

CATALOGUE.HTML
<html>
<head>
<title>catalog</title>
</head>
<body background="2.jpg">
<table border="0"
width="800"
height="300">
<tr>
<td align="center"><img src="wt.jpg" width="70" height="70">
<td align="center">Book:WT<br>Author:nelson<br>Publisher:HiTech
<td align="center">$40
<td align="center"><input type="button" value="add to cart">
</tr>
<tr>
<td align="center"><img src="ai.jpg" width="70" height="70">
<td align="center">Book:AI<br>Author:Russel<br>Publisher:princeton hall
<td align="center">$63
<td align="center"><input type="button" value="add to cart">
</tr>
<tr>
<td align="center"><img src="java.jpg" width="70" height="70">
<td align="center">Book:Java2<br>Author:Watson<br>Publisher:HiTech
<td align="center">$35.5
<td align="center"><input type="button" value="add to cart">
</tr>
</table>
</body>
</html>

REGISTRATION.HTML
<html>
<head>
<TITLE>registration form</title>
<body bgcolor="skyblue">
<center><u><h1>registration form</u></h1>
<form name="myform">
<table border="0">
<tr>
<td>1.name</td>
<td><input type="text" size="25" name="uname"></td>
</tr>
<tr>
<td>2.father name</td>
<td><input type="text" size="25" name="fname"></td>
</tr>
<tr>
<td>3.date of birth</td>
<td><select name="date">
<option value="select" >date</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<select name="month">
<option value="select">month</option>
<option value="jan" >jan</option>
<option value="feb" >feb</option>
<option value="mar" >mar</option></select>
<select name="year">
<option value="select" >year</option>
<option value="19889" >1989</option>
<option value="1990" >1990</option>
<option value="1991" >1991</option>
<option value="1992" >1992</option></select>
</td>
</tr>
<tr>
<td>4.address
<td><textarea rows="10" cols="20" name="addr"></textarea>
</tr>
<tr>
<td>5.gender</td>
<td><input type="radio" name="gender">male
<input type="radio" name="gender">female
</tr>
<tr>
<td>6.mobile number</td>
<td><input type="text" size="25" name="mob"></td>
</tr>
<tr>
<td>7.languages known</td>
<td><table border="0">
<tr><td><input type="checkbox" name="english" size="20" checked>english
<td><input type="checkbox" name="telugu" size="20">telugu
</tr>
<tr>
<td><input type="checkbox" name="tamil" size="20" >tamil
<td><input type="checkbox" name="hindi" size="20" >hindi
</tr>
</table>
</tr>
</table>
<br>
<hr witdh="100%" size="25" color="black">
<input type="submit" value="register">
<input type="reset" value="reset">
</form>
</center>
</body>
</html>

Screens:
TASK 3

VALIDATION: Write JavaScript to validate the following fields of the above registration page.
Name (Name should contains alphabets and the length should not be less than 6 characters).
Password (Password should not be less than 6 characters length). E-mail id (should not contain
any invalid and must follow the standard pattern name@domain.com) Phone number (Phone
number should contain 10 digits only). Note : You can also validate the login page with these
parameters.

<html>
<head>
<script language="jscript">
var nam,flag="select",flag1=0,flag2=0,flag3=0,genflag=0,lanflag=0,str="",n=0,str1="",str2="";
function verifyName()
{
value=document.myform.uname.value;
if(value=="")
alert("enter ur name");
}
function verifyFName()
{
nam=document.myform.fname.value;
if(nam=="")
alert("enter ur father's name");
}
function verifyDate()
{
nam=document.myform.date.value;
if(nam!=flag)
flag1=1;
else
{
flag1=0;
}
}
function verifyMonth()
{
nam=document.myform.month.value;
if(nam!=flag)
flag2=1;
else
{
flag2=0;
}
}
function verifyYear()
{
nam=document.myform.year.value;
if(nam!=flag)
flag3=1;
else
{
flag3=0;
}
}
function verifyDOB()
{
if(flag1!=1||flag2!=1||flag3!=1)
alert("enter dob");
}
function verifyaddr()
{
nam=document.myform.addr.value;
if(nam=="")
alert("enter ur addr");
}
function setFlag()
{
genflag=1;
}
function verifyGen()
{
if(genflag==0)
alert("select gender");
}
function validateMob()
{
str=document.myform.mob.value;
n=str.length;
for(i=0;i<n;i++)
{
s=str.charAt(i);
if(s==1 || s==2|| s=='3' || s=='4' || s=='5' || s=='6' || s=='7' || s=='8' || s=='9' || s=='0'){}
else
{
document.myform.mob.value=str1;
alert("only digits allowed");
str=document.myform.mob.value;
}
}
if(n>10)
{
document.myform.mob.value=str1;
alert("only 10 digits allowed");
str=document.myform.mob.value;
}
str1=str;
}
function verifyMob()
{
lanflag=1;
str=document.myform.mob.value;
n=str.length;
if(str=="" || n<10)
alert("enter mobile no with 10 no's");
}
function verifyLan()
{
str=document.myform.mob.value;
if((lanflag==1 || lanflag==0) && (str!="" && str.length==10)){}
else
alert("enter mobile no with 10 no's ");
}
function register()
{
document.writeln("<br><br><br><br><br><br>ur successfully registered");
}
</script></head>
<body bgcolor="skyblue">
<center><u><h1>registration form</u></h1>
<form name="myform">
<table border="0">
<tr>
<td>1.name</td>
<td><input type="text" size="25" name="uname"></td>
</tr>
<tr>
<td>2.father name</td>
<td><input type="text" size="25" name="fname" OnClick="verifyName()"></td>
</tr>
<tr>
<td>3.date of birth</td>
<td><select name="date" OnClick="verifyFName()" OnChange="verifyDate()">
<option value="select" >date</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<select name="month" OnClick="verifyFName()" OnChange="verifyMonth()">
<option value="select">month</option>
<option value="jan" >jan</option>
<option value="feb" >feb</option>
<option value="mar" >mar</option></select>
<select name="year" OnClick="verifyFName()" OnChange="verifyYear()">
<option value="select" >year</option>
<option value="19889" >1989</option>
<option value="1990" >1990</option>
<option value="1991" >1991</option>
<option value="1992" >1992</option></select>
</td>
</tr>
<tr>
<td>4.address
<td><textarea rows="10" cols="20" name="addr" Onclick="verifyDOB()"></textarea>
</tr>
<tr>
<td>5.gender</td>
<td><input type="radio" name="gender" OnMouseMove="verifyaddr()"
OnClick="setFlag()">male
<input type="radio" name="gender" OnMouseMove="verifyaddr()"
OnClick="setFlag()">female
</tr>
<tr>
<td>6.mobile number</td>
<td><input type="text" size="25" name="mob" OnClick="verifyGen()"
OnKeyUp="validateMob()"></td>
</tr>
<tr>
<td>7.languages known</td>
<td><table border="0">
<tr><td><input type="checkbox" name="english" size="20" OnClick="verifyMob()"
checked>english
<td><input type="checkbox" name="telugu" size="20" OnClick="verifyMob()">telugu
</tr>
<tr>
<td><input type="checkbox" name="tamil" size="20" OnClick="verifyMob()">tamil
<td><input type="checkbox" name="hindi" size="20" OnClick="verifyMob()">hindi
</tr>
</table>
</tr>
</table>
<br>
<hr witdh="100%" size="25" color="black">
<input type="submit" value="register" OnMouseMove="verifyLan()" OnClick="register()">
<input type="reset" value="reset">
</form>
</center>
</body>
</html>

Screens:
TASK 4

Design a web page using CSS (Cascading Style Sheets) which includes the following:

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

EMBEDDED.HTML
<html>
<head>
<style type="text/css">
Div
{
font-family:garamond;
font-size:100px;
color:#fff000;
}
</style>
</head>
<body bgcolor="pink">
<h1><center>Embedded styles</center></h1>
<hr size="10"
color="orange">
<div>SIETK</div><br>
<em><h1>good</h1></em>
<div>work</div>
</body>
</html>

HOVER.HTML
<html>
<head>
<style type="text/css">
a:hover {
font-family:garamond;
color :#gggg;
font-size :200px;
}
</style>
</head>
<body bgcolor="pink">
<center>
<a href="http://www.google.com">GOOGLE</a><br><br><br><br><br>
<a
href="http://www.yahoo.com">YAHOO</a><br><br><br><br><br><br>
<a href="http://www.orkut.com">ORKUT</a>
</center>
</body>
</html>

INLINE.HTML
<html>
<body>
<center>
<b style="font-size:400px;color=#ffff;">css</b>
</center>
</body>
</html>

Screens:

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

BACKGROUND.HTML

<html>
<head>
<style type="text/css">
body {
background-image:url(1.jpg);
background-position:top right;
background-repeat:no-repeat;
background-attachment:nofixed;
}
</style>
</head>
<body>
<center>
<h1>background</h1>
</center>
</body>
</html>

Screens:

C) Define styles for links as A:link A:visited A:active A:hover Example:

<html>
<head>
<style>
a:link {
color: green;
background-color: transparent;
text-decoration: none;
}
a:visited {
color: pink;
background-color: transparent;
text-decoration: none;
}
a:hover {
color: red;
background-color: transparent;
text-decoration: underline;
}
a:active {
color: yellow;
background-color: transparent;
text-decoration: underline;
}
</style>
</head>
<body>

<p>You can change the default colors of links</p>

<a href="html_images.asp" target="_blank">HTML Images</a>

</body>
</html>

Screen:
<html>
<head>
<style type="text/css"></style>
</head>
<body bgcolor="blue">
LAYER 1 ON TOP
<div style="position:relative; font-size:50px;z-index:2;">LAYER 2</div>
<div style="position:relative; top:-50; left:5;color:red;font-size:80px;z-
index:1">LAYER 1</div>
LAYER 2 ON TOP
<div style="position:relative; font-size:50px;z-index:3;">LAYER 1</div>
<div style="position:relative; top:-50;left:5;color:red;font-size:80px;z-
index:4">LAYER 2</div>
</body>
</html>
<html>
<head>
<style type=""text/css">
.xlink{
cursor:crosshair}
.hlink{
cursor:help}
</style>
</head>
<body>
<b>
<a href="C.html"class="xlink">CROSS LINK</a>
<br>
<a href="A.html"class="hlink">HELP LINK</a>
</b>
</body>
</html>
TASK 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.
Note: Give at least for 4 books. It should be valid syntactically

LIB.XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="lib.xsl"?>
<!DOCTYPE note SYSTEM "library.dtd">
<lib>
<book>
<title>C</title>
<author>BALAGURUSWAMY</author>
<isbn-no>9915</isbn-no>
<publisher>Tata-McGrawHill</publisher>
<edition>3rd</edition>
<price>Rs.250</price>
</book>
<book>
<title>Java</title>
<author>HEBERT SCHILDTZ</author>
<isbn-no>3515</isbn-no>
<publisher>Pearson</publisher>
<edition>8th</edition>
<price>Rs.650</price>
</book>
<book>
<title>UML</title>
<author>WILLIAM STALLINGS</author>
<isbn-no>3315</isbn-no>
<publisher>Pearson</publisher>
<edition>3rd</edition>
<price>Rs.300</price>
</book>
<book>
<title>STM</title>
<author>BORIS BEIZER</author>
<isbn-no>9915</isbn-no>
<publisher>Tata-McGrawHill</publisher>
<edition>2nd</edition>
<price>Rs.400</price>
</book>
</lib>

LIB.XSL
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Times New Roman;font-size=10pt;background-color:lightblue">
<br></br>
<br></br>
<br></br>
<center>
<caption>LIBRARY</caption>
<div style="color:red">
<caption>BOOKS</caption>
</div>
<br></br>
<br></br>
<table style="background-color:pink" cellspacing="10" cellpadding="10" border="1">
<tr style="background-color:lightgrey">
<th>TITLE</th>
<th>AUTHOR</th>
<th>ISBN-NO</th>
<th>PUBLISHER</th>
<th>EDITION</th>
<th>PRICE</th>
</tr>
<xsl:for-each select="lib/book">
<tr>
<td style="background-color:lightyellow;text-transform:uppercase"><xsl:value-of
select="title"/></td>
<td style="background-color:lightgreen;font-weight:bold"><xsl:value-of
select="author"/></td>
<td style="background-color:lightyellow"><xsl:value-of select="isbn-no"/></td>
<td style="background-color:lightyellow;text-transform:uppercase"><xsl:value-of
select="publisher"/></td>
<td style="background-color:lightyellow"><xsl:value-of select="edition"/></td>
<td style="background-color:lightyellow"><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>

LIBRARY.DTD
<!ELEMENT lib (book)
<!ELEMENT book (title,author,isbn-no,publisher,edition,price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn-no (#PCDATA)>
<!ELEMENT publisher (PRODUCT,PRICE)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>

Screens:
TASK 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 “.

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(100,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);
}
}
}
TASK 7

Installation of Tomcat and Apache

Here is the Step by Step procedure for installing tomacat:


TASK 8

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.

ADDCOOKIESERVLET.HTML

<html>
<body style="background-color:orange;color:blue">
<form method="get" action="http://localhost:8080/servletauthen/s1">
<h2 align="center">ADD COOKIES</h2>
<table align="center" cellspacing="20">
<tr>
<td><label>Name:<label></td>
<td><input type="text" name="t1"></td>
</tr>
<tr>
<td><label>Value:<label></td>
<td><input type="text" name="t2"></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="ADD COOKIE" name="b1">
</td>
</tr>
</form>
</body>
</html>

ADDCOOKIESERVLET

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name,value;
name=request.getParameter("t1");
value=request.getParameter("t2");
Cookie c=new Cookie(name,value);
response.addCookie(c);
out.println("<html>");
out.println("<head>");
out.println("<script>alert('COOKIE ADDED');</script>");
out.println("</head>");
out.println("<body>");
out.println("<h2>COOKIE DETAILS</h2>");
out.println("<br>Name: "+c.getName());
out.println("<br>Value:"+c.getValue());
out.println("</body>");
out.println("</html>");
}
}

VERIFYCOOKIESERVLET.HTML
<html>
<body bgcolor="cyan">
<form name="f1" method="get" action="http://localhost:8080/servletauthen/s2">
<h2 align="center">LOGIN FORM</h2>
<table align="center" cellspacing="20">
<tr>
<td><b>Login ID:</b></td>
<td><input type="text" name="t1"></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="t2"></td>
</tr>
<tr align="center">
<td><input type="submit" name="b1" value="Submit"></td>
<td><input type="reset" name="b2" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>

VERIFYCOOKIESERVLET.JAVA

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class VerifyCookieServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name,value;
boolean flag=false;
int i,n;
name=request.getParameter("t1");
value=request.getParameter("t2");
Cookie c[]=request.getCookies();
n=c.length;
for(i=0;i<n;i++)
{
if(name.equals(c[i].getName()))
{
if(value.equals(c[i].getValue()))
{
flag=true;
break;
}
}
}
out.println("<html>");
if(flag==true)
out.println("<body><h2>Welcome:
"+c[i].getName()+"</h2></body>");
else
out.println("<body><h2>You are not an authentic
user!</h2></body>");
out.println("</html>");
}
}
WEB.XML
<web-app>
<servlet>
  <servlet-name>GRIET</servlet-name>
  <servlet-class>ServletCookies</servlet-class>
  </servlet>
<servlet-mapping>
  <servlet-name>GRIET</servlet-name>
  <url-pattern>/cook</url-pattern>
  </servlet-mapping>
</web-app>
Screens:
TASK 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).

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.

RESPONSE.JSP
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font color="#FF00FF"><strong>Select query in
JSP</strong></font></h2>
<table align="center" cellpadding="4" cellspacing="4">
<tr>
</tr>
<tr bgcolor="#008000">
<td><b>name</b></td>
<td><b>email</b></td>
<td><b>password</b></td>
<td><b>phone</b></td>
<td><b></b></td>
<td><b></b></td>
</tr>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root",
"admin");
statement = connection.createStatement();
String sql = "SELECT * FROM details";

resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
%>
<tr bgcolor="#8FBC8F">

<td><%=resultSet.getString("name")%></td>
<td><%=resultSet.getString("email")%></td>
<td><%=resultSet.getString("password")%></td>
<td><%=resultSet.getString("phone")%></td>
</tr>
<%
}

} catch (Exception e) {
e.printStackTrace();
}
%>
</table>

Screens:
TASK 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

Insert the details of the user who register with the web site by using the registration form.
Authenticate the user when he submits the login form using the user name and password form
the databse.

REGISTRATION.HTML
<html>
<h1 align="center"><img src="C:\Users\santhosh\Documents\NetBeansProjects\week10 register
and login\hi.jpg">GokaRaju RangaRaju Online Shopping</h1>
<h4 align="center"> Registration Page</h4>
<form action="reg.jsp" method="post">

Email :<input type="text" name="email" />


First name :<input type="text" name="fname" />
Last name :<input type="text" name="lname" />
User name :<input type="text" name="userid" />
Password :<input type="password" name="pwd" />
<input type="submit" />

</form>
</html>

REG.JSP
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("userid");
session.putValue("userid",user);
String pwd=request.getParameter("pwd");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into users values
('"+user+"','"+pwd+"','"+fname+"','"+lname+"','"+email+"')");

%>
<p>Registration sucessfull</p>

LOGIN.HTML
<html>
<head><title>login</title>
</head>
<body>
<h1 align="center"><img src="C:\Users\santhosh\Pictures\hi.jpg">GokaRaju RangaRaju
Online Shopping</h1>
<form action="check.jsp" method="post">
<div align="center">
Username:<input type="text" size="10" name="uname" value=""/><br><br>
Password:<input type="password" size="10" name="pwd" value=""/><br><br>
<input type="submit" value="submit" />
<input type="reset" value="reset"/>
</div>
</form>
</body>
</html>

CHECK.JSP
<%@page language="java" import="java.sql.*" %>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>

<%
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "admin");
statement = connection.createStatement();
String uname=request.getParameter("uname");
String pwd=request.getParameter("pwd");
String sql = "SELECT * FROM users where user_id='"+uname+"' and password='"+pwd+"'";
resultSet = statement.executeQuery(sql);
if(resultSet.next())
out.println("welcome '"+uname+"'!! Login Successfull");
else
{

response.sendRedirect("login.html");
}
}
catch (Exception e) {
e.printStackTrace();
}
%>

Screens:
Registration page
Login page
TASK 11

Create tables in the database which contain the details of items name,price,quantity, amount of
each category. Modify your catalogue page 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.

CATALOG.JSP
<%@page language="java" import="java.sql.*" %>
<%
Connection con=null;
int count=0;
Statement stmt=null;
ResultSet rs=null;
String[] bookname=new String[20];
int[] price=new int[15];
int [] quantity=new int[15];
int[] amount=new int[15];
try{
Class.forName("com.mysql.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
stmt =con.createStatement();
rs=stmt.executeQuery("select * from items");
for(int i=0;rs.next();i++)
{
count++;
bookname[i]=rs.getString(1);
price[i]=rs.getInt(2);
quantity[i]=rs.getInt("quantity");
amount[i]=rs.getInt("amount");
}
if(count!=0)
{
%>
<html>
<title> GRIET ONLINE SHOPPING </title>
<body>

<h1 align="center"><img src="C:\Users\santhosh\Pictures\hi.jpg">GokaRaju RangaRaju Online


Shopping</h1>
<table border="1">
<tr>
<th>BookName</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
<%
for(int j=0;j<count;j++)
{
%>
<tr>
<th><%=bookname[j]%></th>
<th><%=price[j]%></th>
<th><%=quantity[j]%></th>
<th><%=amount[j]%></th>
</tr>
</body>
</html>
<%
}
}
}
catch(Exception e)
{
e.getMessage();
}
%>

Screens:

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

Cart.java

import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class Cart extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
Super.init(config);
}
public void service(HttpServletRequest req,HttpServletResponse res) throws
IOException,ServletException
{
Res.setContentType(“text/html”);
PrintWriter pw=res.getWriter();
HttpSession hs=req.getSession();
ArrayList cart=(ArrayList)hs.getAttribute(“cart”);
If(cart==null)
{
pw.println(“No items in your cart”);
cart=new ArrayList();
hs.setAttribute(“cart”,cart);
}
String itemselected[];
String item;
itemselected=req.getParameterValues(“book”);
if(itemsselected!=null)
{
for(int i=0;i<itemselected.length;i++)
{
item=itemselected[i];
cart.add(item);
}
}
pw.println(“Items in the cart<br>”);
Iterator it=cart.iterator();
while(it.hasNext())
{
pw.println(“<br><b>”+it.next+”</b>”);
}
}
}

Catalogue.java

import java.util.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class Catalogue extends HttpServlet
{
int itemcount=0;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void service(HttpServletRequest req,HttpServletResponse res) throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
HttpSession hs=req.getSession();
ArrayList cart=(ArrayList)hs.getAttribute("cart");
if(cart!=null)
{
itemcount=cart.size();
}
pw.println("you have"+itemcount+"items in cart");
pw.println("<body><center><fieldset><legend>Catalogue</legend><form action='cart'
method='get'><input type='checkbox' value='Java2' name='boo'>Java2</input><br>");
pw.println("<input type='checkbox' name='book' value='web programming'>Web
Programming</input><br>");
pw.println("<input type='checkbox' name='book' value='Java2 Complete Reference'>Java2
Complete Reference</input><br>");
pw.println("<input type='checkbox' name='book' value='Internet & World wide web'>Internet &
World wide web</input><br>");
pw.println("<input type='checkbox' name='book' value='Core Servlets & JSP'>Core Servlets &
JSP</input><br>");
pw.println("<input type='checkbox' name='book' value='J2EE 3rd Edition'>J2EE 3rd
Edition</input><br>");
pw.println("<input type='checkbox' name='book' value='Sofware Engineering'>Sofware
Engineering</input><br>");
pw.println("<input type='checkbox' name='book' value='Computer Networks'>Computer
Networks</input><br>");
pw.println("<input type='checkbox' name='book' value='Software Project
Management'>Software Project Management</input><br>");
pw.println("<input type='checkbox' name='book' value='Design and analysis of
Algorithms'>Design and analysis of Algorithms</input><br>");
pw.println("</fieldset></center>");
pw.println("<input type='submit' value='submit'>");
}
}

Вам также может понравиться