• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

show cart in shopping cart

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Preeti Sikri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys pls help me out with the above code
Regards Preeti
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preeti,
I would suggest u to use useBean approach, instead wht u have done.. bec it's very simple to achieve wht u want, by that approach..
If u want i can send the codes..
If u r particular abt this approach, i think i need more time to trace the problem..
Saran
 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've already worked on a similar situation .
i've userd the same variable's as you have and have used beans with jsp ..
the idea is to store all the items into a vector and call the vector into the jsp .....when you get all the items into jsp you can get them by using the loop and in that loop you can declare the same amount of checkboxes .....the next step would be to select the items and get them in your cart ....you'll be passing just one(1)value to the cart page (it can be any value ...may be the id number i.e:- 1,2, 5)...so 1 , 2 , 5 will be passed to the next page that is the cart page .
Once you get the id numbers you can get all the info corresponding to the id numbers and for that you have to write a function :---
public classname getAll(int idumber)
{
return (classname)items.elementAt(idnumber);
}

try this out ...if you still face prob , mail me at [email protected].
 
Preeti Sikri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi saran
It will be great if u can send me the sample code
Thanks in advance
Regards Preeti
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic