pro_jsp thread: another problem in Shopping cart .... This is very urgent ... help
Hey guys pls solve this problem
I want to create a shopping cart and this is my first page on which I'm
showing list of all the products and when somebody says add to cart it
refreshes the same page and add the book_id to the vector now it is
showing me a problem when I first enter the page and the errors are :-
1. javax.servlet.ServletException: null
2. Root cause: java.lang.NumberFormatException: null
code for my jsp page is :
<%@page language=3D"java" import=3D"java.util.*"%>
<%@page import=3D"shop.disBean"%>
<%@page import=3D"shop.cart"%>
<HTML>
<HEAD>
<TITLE>
Display Products
</TITLE>
</HEAD>
<BODY topmargin=3D"0" leftmargin=3D"0">
<table cellspacing=3D"2" cellpadding=3D"2" border=3D"1">
<tr>
List of Book
<table border=3D"3">
<tr>
<td>Book Name</td>
<td>Price</td>
<td>Publisher</td>
<td>CD</td>
<td>Category Name</td>
<td>Buy</td>
</tr>
<%--int ibook_id;--%>
<% Vector vect=3Dnew Vector();
cart newcart =3D new cart();
disBean disB=3Dnew disBean();
disB.connect();
vect=3DdisB.query();
int size=3Dvect.size();
for(int i=3D0;i<size;i++)
{
Object refObj=3Dvect.elementAt(i);
disBean strRecord=3D(disBean) refObj;
%>
<tr>
<td><%=3D strRecord.getBook_name()%></a></td>
<td><%=3D strRecord.getPrice()%></td>
<td><%=3D strRecord.getPublisher() %></td>
<td><%=3D strRecord.getCd() %></td>
<td><%=3D strRecord.getCategory_name() %></td>
<td><a href=3D"dis.jsp?book_id=3D<%=3DstrRecord.getBook_id()%>">add to
cart</a></td>
</tr>
<%
}%>
</table>
</td></tr></table>
<%
int BookId =3D Integer.parseInt(request.getParameter("book_id"));
if(BookId !=3D 0) {
out.println("Id u chossed is " + BookId);
newcart.addtocart(BookId);
}
%>
</BODY>
</HTML>
and my Bean cart is :
package shop;
import java.util.*;
public class cart{
Vector list =3D new Vector();
public cart(){
list =3D new Vector();
}
public String addtocart(int id)
{
if(id > 0)
{
list.addElement(new Integer(id));
}
return "added to vector";
}
}
pls help me
Thanks in advance
Preeti