Está en la página 1de 6

Online

Shopping

PSUEDO CODE OF THE SERVLETS:

In loginServlet mainly we are doing three tasks:

When the existed customer enters his ID and PASSWORD, it


is checked with the database for the validity. If the customer gives
incorrect ID, then he is informed with the message and he has to
relogin. If the customer gives incorrect password then he has to
relogin and correct his password. The Administrator maintains a
record of every user who visits our site.

To check for the validity of the existed user


we connect to the database as follows:

try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Con=DriverManager.getConnection("jdbc
:odbc:batch",
"batch10","batch10");
S=con.createStatement ();
stmt=con.createStatement ();
rs=s.executeQuery("select * from custregistration");

While (rs.next ())


{
String str1=rs.getString(2);
String str=rs.getString (3);
If (user_id==null&&password==null)
{
if(sessionid!=null)
{

a=sessionid.length ();
sessionid=sessionid.substring
(1,a);
break;
}
}

54

Dept of C.S.E.,Narayana Engineering


College.,Nellore.
Online
Shopping

 We are creating the session_id to track the user throughout the


shopping:
If the session_id is null, then generate the session_id as follows

if(sessionid==null)
sessionid=user_id;

if (user_id.equals("smartshoppee")
&&password. equals(str))

{ flag=3; break; }

//checking the user_id and password for validity:

if(user_id.equals(str1))
{f=1;
if(password. equals(str))
{ }
else
{
out.println("<font color
=green size=8>Invalid password try again</font><br><div align
=right>");
out.println("<a
href=c:/javawebserver2.0/public_html/lgon.html>login</a></div>");
flag=10;
break;
}
}
if(f==1&&!password.equals(str))
{
out.println("<font color
=blue size=8>Invalid User Id try again</font><br><div align =right>");
out.println("<a
href=c:/javawebserver2.0/public_html/lgon.html>login</a></div>");
break;
}else if (flag==0) {flag=5;}

55

Dept of C.S.E.,Narayana Engineering


College.,Nellore.
Online
Shopping

The record of the users visiting our site is maintained as follows:

if(user_id.equals(str1)&&password.equals(str))
{
row=stmt.executeUpdate ("insert into login
values('"+user_id+"','"+password+"')");
con.commit ();
}
After login the customer is provided with the list of items like
FLOWERS, GIFTARTICLES, ELECTRONICS, JEWELLERY etc. After
clicking the particular item the reference to the next servlet is as
follows:

//here the reference is back to the homepage:


out.println("<MAP name=map>");
out.println("<AREA alt=home coords=162,5,271,19
href=http://localhost:8080/servlet/loginServlet shape=RECT
name=link1>");
//reference to the FServlet where flowers are present:
out.println("<AREA alt=click for getting flowers coords=283,5,393,19
href=http://localhost:8080/servlet/FServlet/" + sessionid +"
shape=RECT name=link2>");
reference to the EServlet where electronics are present:
out.println ("<AREA alt=click for getting Electronics
coords=409,5,535,19 href=http://localhost:8080/servlet/EServlet/" +
sessionid + " shape=RECT name=link3>");
//reference to the GServlet where gift Articles are present :
out.println("<AREA alt=click for getting Gift Articles
coords=551,5,688,19 href=http://localhost:8080/servlet/GServlet/" +
sessionid + " shape=RECT name=link4>");
//reference to the JServlet where jewellery are present :

56

Dept of C.S.E.,Narayana Engineering


College.,Nellore.
Online
Shopping

out.println("<AREA alt=click for getting Jewellery coords=704,5,801,19


href=http://localhost:8080/servlet/JServlet/" + sessionid + "
shape=RECT name=link5>");
If the customer is new then he has to sign in at new user:

out.println("<h3><i><font color=Black >If


you are not exist user then sign in at new user</font></i></h3>");
out.println("<i>for relogin press </i>");
out.println("<div align=right>");
out.println("<a
href=c:/javawebserver2.0/public_html/lgon.html>logon</a>");
out.println("</div>");
out.println("If you are existed the login
<br><i>To register click registration</i>");
out.println("<div align=right>");
out.println("<a
href=c:/javawebserver2.0/public_html/reg.html>registration</a>");

out.println("</div>");
//the reference for the signout is follows:

out.println("<div align=right><font size=3>You are loggined


'"+user_id+"' [</font><a href=signout.html><font size=2
color=red><i>sign out</i></font><font size=3>]</font></div>");
REGISTRATION SERVLET:
 The HTML for the registration form is as follows:
<html>
<head>
<title>REGISTRATION FORM</title>
</head>
57

Dept of C.S.E.,Narayana Engineering


College.,Nellore.
Online
Shopping

<BODY bgColor="#FFFF99">
<img border="0" src="untitled.gif" width="487"
height="105"><font color="#FF00FF"><marquee><strong><i>shop for
online shoppers</i></strong></marquee>

</font>
<hr align="left" color="#FF0000">
<table border="0" size="100%"
width="100%"><tr><th width="100%" align="left" colspan="2">
<th width="50%" align="left">
<strong><i><font size="2"
color="#000000">In our shop we&nbsp; provide the following:
(Flowers, Electronics,Books,Jewellery Gift
Articles etc.)</font></i></strong>
</table>

<H3 align="center"> REGISTRATION FORM </H3>

<formmethod="get"
action="http://localhost:8080/servlet/regs" onSubmit="">
<table border="0" width="100%">
<tr>

<td width="22%" align="right"><strong><i>User


Name:</i></strong><font color="red">*</font></td>
<td width="45%" align="left"><input type="text"
name="name"></td>
</tr>

58

Dept of C.S.E.,Narayana Engineering


College.,Nellore.
Online
Shopping

 The parameters given by the new customer in the registration form are
received by the next servlet as follows:
String name=req.getParameter("name");
String userid=req.getParameter("userid");
String password=req.getParameter("password");
String address=req.getParameter("address");
String city=req.getParameter("city");
String state=req.getParameter("state");
String pincode=req.getParameter("pincode");
String email=req.getParameter("email");

The parameters in the registration are inserted into the custregistration


table for the reference by the Administrator.

row=Stmt.executeUpdate("insert into custregistration


values('"+name+"','"+userid+"','"+password+"','"+address+"','"+city+"','"
+state+"','"+pincode+"','"+email+"')");
After inserting the connection must be closed.
con.commit ();

59

Dept of C.S.E.,Narayana Engineering


College.,Nellore.

También podría gustarte