Hi friends
I am very new to
jsp and I have to create a shopping cart .
now i have done till add to cart now I have to do show cart
now in the following steps I'll tell u what I wanna do :
1. add to cart : to store the book id in a vector ..
2. show cart : when somebody say show cart I wanna select the all products for which I have the id stored in a vector
Now I do not know how to achieve show cart functionality ...
I 'm attaching my jsp code and my cart bean so guys pls help me out in making the show cart working pls ......
and do tell me if i need to working with set and get method in my cart file
code for the JSP file :
<%@page language="java" import="java.util.*"%>
<%@page import="shop.disBean"%>
<%@page import="shop.cart"%>
<HTML>
<HEAD>
<TITLE>
Display Products
</TITLE>
</HEAD>
<BODY topmargin="0" leftmargin="0">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
List of Book
<table border="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=new Vector();
cart newcart = new cart();
disBean disB=new disBean();
disB.connect();
vect=disB.query();
int size=vect.size();
for(int i=0;i<size;i++)
{
Object refObj=vect.elementAt(i);
disBean strRecord=(disBean) refObj;
%>
<tr>
<td><%= strRecord.getBook_name()%></a></td>
<td><%= strRecord.getPrice()%></td>
<td><%= strRecord.getPublisher() %></td>
<td><%= strRecord.getCd() %></td>
<td><%= strRecord.getCategory_name() %></td>
<td><a href="dis.jsp?book_id=<%=strRecord.getBook_id()%>">add to cart</a></td>
</tr>
<%
}%>
</table>
</td></tr></table>
<%
String s = request.getParameter("book_id");
int BookId;
if (s != null ){
BookId = Integer.parseInt(s);
out.println("Id u chossed is " + BookId);
newcart.addtocart(BookId);%>
<br>
<form action="show.jsp" method="post">
<input type=submit value="show cart">
</form>
<%
}
%>
</BODY>
</HTML>
show.jsp is (I guess i need to work with this file properly)
<HTML>
<HEAD>
<jsp:useBean id="cartBean" scope="session" class="shop.cart" />
<jsp:setProperty name="cartBean" property="*" />
<TITLE>
show
</TITLE>
</HEAD>
<BODY BGCOLOR="#ffc800">
showing products in the cart:
<%
if (cartBean.getSize() > 0 )
{
out.print("will be showing all the products");
}
%>
</BODY>
</HTML>
and my cart.java is
package shop;
import java.util.*;
public class cart{
Vector list = new Vector();
file://int id = 4;
public cart(){
list = new Vector();
}
public Vector addtocart(int id)
{
if(id > 0)
{
list.addElement(new Integer(id));
}
return list;
}
public int getSize()
{
int size = list.size();
return size;
}
/*
public void showcart()
{
int size=list.size();
for(int i=0;i<size;i++)
{
System.out.println(list.elementAt(i));
}
}*/
}
pls help me out
Regards Preeti