Hi:

I'm trying to put together a simple Shopping Cart, but get an error along the lines of:

Exception in jsp:
javax.servlet.ServletException at 
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:367)
 at _0005cbasket_0002ejspbasket_jsp_0._jspService(_0005cbasket...

What is the problem here - what's the business with PageContext? - and how do I 
resolve it?  Thanks in advance if you're taking the time to look at this.  Here's what 
my code basically looks like (I've highlighted the offending line).

First, I have shop.jsp which sets up an object of type ShoppingCart:

if (session.getValue("ShoppingCart") == null)
{
 ShoppingCart cart = new ShoppingCart();
 session.putValue("ShoppingCart", cart);
}

Then I have basket.jsp which attempts to add an item of type ShoppingItem

ShoppingItem aShoppingItem = new ShoppingItem(selectedItem);
 ShoppingCart cart = (ShoppingCart) session.getValue("ShoppingCart");
 cart.AddItem(aShoppingItem); // offending line!
 session.putValue("ShoppingCart", cart);


basket.jsp is where I get the error in page compilation.
Here are my two class definitions:

package extra;

import java.util.*;

public class ShoppingCart
{
 Vector listOfItems;

 public ShoppingCart()
 {
  listOfItems = null;
 }

 public void AddItem(ShoppingItem anItem)
 {
  listOfItems.addElement(anItem);
 }
}

package extra;

public class ShoppingItem
{
 private String itemName;

 public ShoppingItem()
 {
  itemName = null;
 }

 public ShoppingItem (String anItemName)
 {
  itemName = anItemName;
 }
}

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to