Administrator

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Administrator as PDF for free.

More details

  • Words: 1,485
  • Pages: 16
Onlline Shopping

The administrator is the owner of the shop who can view the items in his shop, insert the items and can delete the items. To insert the items in the shop he has to specify the itemcode, itemname, number of items he want, and the cost of the item. The HTML page for inserting the items by the Administrator is: The psuedo code for inserting the item is: String code=req.getParameter("itemcode"); String path=req.getParameter("itemspath"); String idis=req.getParameter("itemdesc"); Int totalno=Integer. parseInt(req.getParameter("noofitems")) String name=req.getParameter ("itemname"); int a =Integer.parseInt(req.getParameter("cost")); res.setContentType("text/html"); PrintWriter out=res.getWriter(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection ("jdbc:odbc:batch","batch10","batch10"); stmt=con.createStatement(); row=stmt.executeUpdate("insert

into

itemlist

values('"+code+"','"+path+"','"+name+"',"+totalno+",'"+idis+"',"+a+")"); Con.commit (); For deleting a particular item he has to specify the itemcode of the item. String itemcode=req.getParameter("itemcode"); PrintWriter out=res.getWriter(); res.setContentType("text/html"); out.println("loginError"); out.println("");

60 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println("<marquee><strong>shop for online shoppers
"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:batch","batch10","bath1 0");

stmt=con.createStatement();

s=con.createStatement(); row=stmt.executeUpdate("delete from itemlist where itemcode='"+itemcode+"' "); con.commit(); } catch(ClassNotFoundException e) {

System.out.println("CNFE ," +e);

} If the Itemcode specified is not correct then the exception is raised saying that the Itemcode is not correct. catch(SQLException e) { out.println("SELECT

PROPER

ITEMCODE

TO

DELETE"); out.println("del et item"); } Another exception is raised If the administrator doesn’t specify the itemcode and clicks the Delete button. catch(NullPointerException e) { out.println("ENTER ITEMCODE TO DELETE");

61 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println("del et item"); After clicking the FLOWERS button all the flowers in the shop are displayed in the Fservlet as follows: rs = stmt.executeQuery("select * from itemlist where itemcode>'f000' and itemcode<='f9999'"); out.println("Flowers"); out.println

("
src=c:/javawebserver2.0/public_html/lgon_files/untitled.gif>
"); The table for inserting the items is: while(rs.next()) { itemcode[count]=rs.getString(1); count[count]=rs.getFloat(6); count=count+1; out.println(""); out.println(""); if(count==6) break; } out.println(""); out.println(""); for(j=0;jIc:"+itemcode[j]+""); out.println(""); out.println(""); 62 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

for(j=0;jRs:"+cost[j]+" "); out.println(""); out.println(""); for(j=0;j
bgcolor=#ffff99>
color=black>"); out.println(""); out.println(""); for(j=0;j"); out.println(""); out.println("
"); out.println(""); } out.println(""); } Similarly

the

code

for

every

item

to

display

is

same.i.e;for

ELECTRONICS, GIFT ARTICLES, JEWELLERY etc. After clicking the buy button the customer has to specify the quantity he want. After clicking the submit button the quantity is added to his cart. He is also provided with three options like ADDMORE,VIEWCART AND BILL. Mere clicking the ADDMORE button he can add more items to his cart. The Servlet for receiving the quantity: out.println("");

63 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println("Name:"); out.println("<spanstyle=texttransform:uppercase>" +rs.getString(3)+""); out.println(""); out.println("
size=2

color=black>Quantity:"); out.println(""); out.println(""); out.println(""); out.println("
"); out.println("
"); out.println(""); out.println(""); If the customer want to buy the same item then the servlet is: while (rs1.next()) { if(code.equals(rs1.getString(1))&&sessionid.equals(rs1.getStrin g(3))) { out.println("This item is already added to your cart
"); out.println("<marquee>YOUR ITEM IS

SUCCESSFULLY ADDED TO YOUR

CART
"); out.println("You want to add more item to your

cart click on Addmore
"); out.println("
ervlet/loginServlet/" + sessionid + ">"); out.println("
"); 64 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println(""); out.println("You want to view the addcart click on ViewACart"); out.println("
method

=get

action=http://localhost:8080/servlet/ViewACartServlet/" + sessionid + "> "); out.println("
align=

center

>
type=submit

value= ViewACart>
"); out.println(""); out.println("You want bill");

out.println(""); out.println("
"); The Servlet to View the items is : out.println("
"); while(rs.next()) { String code1 =rs.getString(1); int cont=rs.getInt(2); String ci=rs.getString(3); If(sessionid.equals(ci)) { rs1=s.executeQuery("select * from itemlist"); while(rs1.next()) { String code=rs1.getString(1); 65 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

String name=rs1.getString(3); String desc=rs1.getString(5); if(code.equals(code1)) { out.println(""); out.println("
'"+code+"'
'"+name+"'
"+desc+"'
"+cont+"
"); } } } } out.println(""); out.println("To Modify click submit
"); out.println("
"); out.println("
"); out.println("
"); out.println("
"); The customer can modify the quantity he specified. Before that he has to select the items he has to modify and click the modify button. while(enume.hasMoreElements()) { String name1=(String) enume.nextElement (); String values []=req.getParameterValues (name1); 66 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

if(values!=null) for(int i=0;i
rs=stmt.executeQuery("select * from temp1 where

custid='"+sessionid+"'");

while(rs.next())

{ String code1=rs.getString(1); int cont=rs.getInt(2); if(values[i].equals(code1)) { rs1=s.executeQuery("selectfromitemlistwhereitemcode='"+values[i]+"'" );

while(rs1.next()) { String code=rs1.getString (1); String name=rs1.getString (3); String desc=rs1.getString(5); out.println("
name='"+code+"' value='"+code+"'
"); out.println("
"); String t=code.concat ("/"); Out.println(""); } } } } The servlet for modifying the quantity and deleting the item the

customer has selected.

stmt.executeUpdate("update temp1 set count="+a+" where ic='"+code1+"' and custid='"+sessionid+"'");

67 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

r=stmt.executeUpdate("delete from temp1 where ic='"+values[i]+"' and custid='"+sessionid+"'"); After buying all the items the bill format is displayed by clicking the bill button. The servlet for the bill format is: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:batch","batch10","batch 10");

stmt=con.createStatement();

s=con.createStatement(); rs=stmt.executeQuery("select

*

from

temp1

where

custid='"+sessionid+"'"); while(rs.next()) { String code1 =rs.getString(1); int cont=rs.getInt(2); String name1=rs.getString(3); rs1=s.executeQuery("select * from item list"); while(rs1.next()) { String code=rs1.getString(1); String name=rs1.getString(3); int toc =rs1.getInt(4); String desc=rs1.getString(5); float cost=rs1.getFloat(6); if(code.equals(code1)) { x++; tco=cont * cost; fco=fco+tco; 68 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

y=y+cont; out.println("
"+x+"
'"+code+"'
'"+name+"'
"+desc+"'
"+cont+"
"+cost+"
"+tco+"
"); } } } out.println("
FINAL COST :
"+fco+"
"); out.println("
"); out.println("
"); out.println("
"); out.println("TOTAL NUMBER OF ITEMS:"); out.println("
color=red

size=3>

"+x+"

"); out.println("
color=black

size=3>FINAL

QUANTITY:
"); out.println(" "+y+""); st=con.createStatement(); r=st.executeUpdate("insert

into

total

values('"+sessionid+"',"+fco+")"); con.commit();

69 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println("
"); After billing when the customer clicks the Checkout button the servlet Checkout is invoked where the customer credit card number is taken and is checked with the Bank database. out.println("
align=right>
type=submit

value=Checkout>
"); out.println(""); } The Check out servlet where the customer enters his Credit card number. Public class checkOutservlet extends HttpServlet { Public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String sessionid=req.getPathInfo (); int a=sessionid.length(); res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.println ("buy item"); out.println (""); Out.println(""); out.println("<MARQUEE><STRONG>shop

for

online

shoppers
"); out.println("
"); 70 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

out.println("
BILL REPORT
"); if(sessionid!=null) { sessionid=sessionid.substring(1,a); out.println("
method=get

action=http://localhost:8080/servlet/check/" + sessionid + ">"); out.println("
align=center>
border=0

width=53%>"); out.println("Credit Card id:"); out.println("
"); out.println("
align=right>
type=submit

name=submit value=submit>"); } } After giving the credit card number, when the customer clicks the Check out button the servlet invoked is Check servlet where the validity of the credit card is checked. public class check extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { Connection con=null; Statement stmt=null; Statement s=null,s1=null; Result Set rs=null; ResultSet rs1=null,rs2=null; int count=0,r,x=0,y=0,flag=0; String cri =req.getParameter("t1"); 71 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

String sessionid=req.getPathInfo(); int a=sessionid.length(); float tco=0,fco=0; res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.println("buy item"); out.println(""); out.println(""); out.println("<MARQUEE><STRONG>shop

for

online

shoppers
"); out.println("
"); out.println("
BILL REPORT
");

if(sessionid!=null) { sessionid=sessionid.substring(1,a); out.println("
CUSTOMER

align=center>
size=2 size

=3

color=red>'"+sessionid+"'
"); To check the validity of the credit card number and to know the amount in his credit, the servlet code is: try { Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:batch"," batch10","batch10"); stmt=con.createStatement(); 72 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

s=con.createStatement(); s1=con.createStatement(); rs=stmt.executeQuery("select*from

total

where

userid='"+sessionid+"' "); rs.next(); float aa=rs.getFloat(2); rs1=s.executeQuery("select*from

bankdb

where

creditno='"+cri+"'"); rs1.next(); double bb=rs1.getDouble(3); If the amount of the customer is allowable then the bank database is updated by taking the amount from his bill

and

displaying a message stating, “your shopping is successful”. The product will be delivered to the delivery date given by the shopper. if(aa
bankdb

set

amount="+bb+" where creditno='"+cri+"'"); con.commit(); out.println("
YOUR

align=center>
SHOPPING

IS

size=5

SUCCESSFULLY

COMPLETED
"); out.println("
align=center>
size=7

color=green>YOUR ITEMS WILL BE DELIVERED AS EARLY AS POSSIBLE"); out.println("
+

sessionid

+

" rel="nofollow">signout
"); r=s1.executeUpdate("delete from temp1"); con.commit(); r=s1.executeUpdate("delete from total"); 73 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

con.commit(); }else If the credit of the customer is not allowable then the exception is raised saying that YOU HAVE NOT ENOUGH MONEY TO PURHASE THE ITEMS and to check your amount again. { out.println("
align=center>
size=5

color=blue> YOU HAVE NOT ENOUGH MONEY"); out.println("
PLEASE

CHECK

align=center>
AGAIN

size=10 YOUR

AMOUNT
"); out.println("
align=left>
size=4

+

sessionid

+

color=black>try

again
"); out.println("
Sign out
"); } } catch(ClassNotFoundException e) { System.out.println("CNFE ," +e); } catch(SQLException e) { flag=1; } finally { try { 74 Dept of C.S.E., Narayana Engineering College.,Nellore.

Onlline Shopping

if(con!=null) con.close(); }catch(SQLException ignored) {

}

} } If the customer’s credit card number is not valid i.e., the credit card number is not in the Bank database, then a exception is raised stating “your credit card number is not valid” if(flag==1) { out.println("Enter the Valid credit card number
"); out.println("
align

href=http://localhost:8080/servlet/checkOutservlet/"

=right>
sessionid

+

" rel="nofollow">click here to go back
"); } } }

75 Dept of C.S.E., Narayana Engineering College.,Nellore.

Related Documents

Administrator
November 2019 37
System Administrator
June 2020 3
Administrator 2.0
June 2020 1
Administrator Guide
August 2019 35
Administrator Guide
December 2019 28
System Administrator
April 2020 12