dear ones i am doing project in online shopping.my project contains store for books,cars,watches etc.my problem is how to develop a shopping cart which shows deatils about items selected when user clicks addto bag here is my sample html page which is a bookstore <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFCC" text="#000000"> <font size="+1">1. Java Servlets</font> <pre align="left"><font size="+1"> <b>Author :Karl Moss Price :275.00 Publisher : ID :12457 <font size="-1"> <a href="/servlet/showbag?bookid=12457&bname=java servlets&price=275.00" target="_blank" >Add to Bag</a></font></b></font></pre> <hr> <p align="left"><font size="+1">2.Java Server Pages</font></p> <div align="left"> <pre><font size="+1"><b>Author : Price : Publisher : ID : 12359 <a href="/servlet/showbag?bookid=12359&bname=Java Server Pages&price=456.00" target="_blank"><font size="-1">Add to Bag</font></a></b></font></pre> <hr> <h3><font size="+1">3.Programming in C</font></h3> <pre><font size="+1"><b>Author :Balaguruswamy P</b></font><b><font size="+1">rice :150.00 Publisher :</font> <font size="+1">ID :12358 <font size="-1"> <a href="/servlet/bk1?bookid=12358" target="_blank">Add to Bag</a></font></font></b></pre> <hr> <p><b><font size="+1">4.Visual C++</font></b></p> <pre><b><font size="+1">Author : </font></b><b><font size="+1">Price : </font></b><b><font size="+1">Publisher :</font></b> <b><font size="+1">ID :12369 <a href="/servlet/bk1?bookid=12369" target="_blank"><font size="-1">Add to bag</font></a></font></b></pre> <hr> <h2>5.Computer Networks</h2> <pre><font size="3"><b><font size="+1">Author :Tannenbaum Price :200 Publisher: ID : 12457 </font><font size="3"><b><font size="+1"> <font size="-1"><a href="/servlet/bk1?bookid=12459" target="_blank">Add to bag</a></font></font></b></font></b></font></pre> <hr> <pre><font size="3"><b><font size="+1"> </font><font size="3"><b><font size="3"><b><font size="+1"><a href="page3.htm" target="_blank"><img src="home.jpg" width="160" height="34" border="0"></a></font></b></font></b></font></b></font></pre> </div> </body> </html> ihave written one servlet for shopping cart but shows error500 the servler is package onlineshop; // import online.BooksDetails; import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ShowCartServlet extends HttpServlet { public BooksDetails cart; public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("ppp"); HttpSession session=request.getSession(true); cart=(BooksDetails)session.getValue(session.getId());
if (cart == null) { cart = new BooksDetails(); session.putValue(session.getId(), cart); }
addCart(request); showCart(out); } private void addCart(HttpServletRequest request) { int units=1; String bookid=request.getParameter("bookid"); double price=Double.valueOf(request.getParameter("price")).doubleValue(); String bname =request.getParameter("bname"); cart.additem(bname,bookid,units,price); } private void showCart(PrintWriter out) { //out.println("<center><br><p><font color=red>Your user ID: "+cart.cid+"<br><br>"); // show empty info if there's nothing in shopping cart if (cart.totalItems==0){ out.println("<h3><font color=yellow>Sorry, there's nothing in your shopping cart yet!</font></h3>");} else { out.println("<center><table border=4 background=\"/bg.gif\" width = 90% >"); out.println("<tr>"); out.println("<td><b><font color=red><center>Bookname</center></font></b></td>"); out.println("<td><b><font color=red><center>Bookid</center></font></b></td>"); out.println("<td><b><font color=red><center>Price</center></font></b></td>"); out.println("<td><b><font color=red><center>Quantity</center></font></b></td>"); out.println("<td><b><font color=red><center>SubAmount</center></font></b></td>"); out.println("</tr>"); for (int i = 0; i < cart.totalItems; i++){ out.println("<tr>"); out.println("<td><b><font color=blue><center> "+cart.bname[i]+" </center></font></b></td>"); out.println("<td><b><font color=blue><center> "+cart.bookid[i]+" </center></font></b></td>"); out.println("<td><b><font color=blue><center> "+cart.unitprice[i]+" </center></font></b></td>"); out.println("<td><b><font color=blue><center> $"+cart.units[i]+" </center></font></b></td>"); out.println("<td><b><font color=blue><center> $"+cart.stotal[i]+" </center></font></b></td>"); out.println("</tr>"); } out.println("</table>"); } }
// package online; // import java.io.*; // import java.util.*; class BooksDetails { public String[] bname; public String[] author; public String[] bookid; public int[] units; public double[] unitprice; public double[] stotal; public double totalPrice =0; public int cid=0; public String password=""; public int maxItems = 100; public int totalItems =0;
public void BooksDetails() { bname=new String[maxItems]; author=new String[maxItems]; units=new int[maxItems]; bookid=new String[maxItems]; stotal=new double[maxItems]; } public BooksDetails additem(String bname,String bookid,int units,double unitprice) { if(!found(bookid)) { this.bname[totalItems]=bname; this.bookid[totalItems]=bookid; this.units[totalItems]=units; this.unitprice[totalItems]=unitprice; this.stotal[totalItems]=units*unitprice; totalItems++; } totalPrice=getPrice(); return this; } public boolean found(String bookid) { for(int i=0;i<totalItems;i++) { if (this.bookid[i].equals(bookid)) { this.units[i]++; this.stotal[i]=this.units[i]*this.unitprice[i]; return true; } } return false; } public String[] showCart() { String[] s = new String[totalItems]; for (int i = 0; i < totalItems; i++) { s[i] = "<td><center> "+bname[i]+" </center></td>"; s[i] += "<td><center> "+bookid[i]+" </center></td>"; s[i] += "<td><center> $"+unitprice[i]+" </center></td>"; s[i] += "<td><center><input type=\"text\" size=\"5\" name=\"items\"> "+units[i]+" </center></td>"; s[i] += "<td><center> $;"+stotal[i]+" </center></td>"; } return s; } public double getPrice() { double p = 0.0; for (int i = 0; i < totalItems; i++){ p += units[i]*unitprice[i]; } return p; } } please help m with correction if possible or a new source code for the shopping cart