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
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("
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.
"); 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
out.println(""); out.println(""); The Servlet to View the items is : 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]+"'" );
"); 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");
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.
"); 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.
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("
} } 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