ArrayList using JavaBean and JSP-URGENT
843838Nov 7 2005 — edited Apr 20 2008I have a simple shopping cart problem which needs attention asap (deadline issue).
Here is the code to a page which collects information about the product:
<<jsp:useBean id="cart" class="shoppingcart.OrderItem" scope="session" />
...
form method="post" action="shopping_cart.jsp" >
<p>
<input name="product" type="hidden" id="product" value="New Phone Install">
1. How many new commercial phones would you like to have installed?
<input name="quantity" type="text" id="quantity" size="4" maxlength="4">
</p>
<p>2. Additional Information (optional):</p>
<p>
<textarea name="misc" cols="100" rows="3" id="misc"></textarea>
</p>
<input name="submit" type="submit" id="Add to Cart" value="add">
</p>
</form>
It then gets passed to my OrderItem bean:
package shoppingcart;
import java.util.*;
public class OrderItem {
private String product;
private int quantity;
private String misc;
/****
****************/
public String getMisc() {
return misc;
}
public void setMisc(String misc) {
this.misc = misc;
}
/****
****************/
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product=product;
}
/****
****************/
public int getQuantity() {
return quantity;
}
/*********
* Some validation
********/
public void setQuantity(int quantity) {
this.quantity=quantity;
}
/****
****************/
}
Here's where I run into problems>I need to set up an ArrayList either in this bean or another bean that displays product, quantity, misc in a nice tablular format in a page called shoppingcart.jsp.
Here's what I have for shoppingcart.jsp:
<jsp:useBean id="cart" class="shoppingcart.OrderItem" scope="session" />
<jsp:setProperty name="cart" property="*" />
...
<!---begin row for shopping cart entries --->
<tr class="text">
<td class="text"><%=cart.getProduct() %> </td>
<td align="center" class="text"><%=cart.getQuantity() %> </td>
<td><%=cart.getMisc() %></td>
<td align="center"><input type="submit" name="Submit" value="Remove"></td>
<td align="center"><input name="Submit" type="submit" value="Update"></td>
</tr>
<!---End row for shopping cart ---->
The shoppingcart.jsp displays what I need but only for one product at a time, not a list which is what I'm looking for.
This doesn't seem very hard but I cannot figure it out. If anyone can help, it'd be greatly appreciated!
TIA