购物车中的javax.el.PropertyNotFoundException

时间:2014-05-30 06:34:30

标签: java jsp servlets jstl javabeans

我正在购买购物车但是当我尝试显示购物车的内容时,它会给我一个名为 HTTP状态500的错误 - javax.el.PropertyNotFoundException:Property' IdNumber'在Cart.CartItemBean类型上找不到 我在Jsp上使用bean来显示购物车的内容。

ShoppingCart.jsp

    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
         <title>Shopping Cart</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>

        <p><font face="Verdana, Arial, Helvetica, sans-serif"><strong>Shopping Cart</strong></font></p>
        <p><a href="ModelList.jsp" mce_href="ModelList.jsp">Model List</a> </p>
        <table width="75%" border="1">
            <tr bgcolor="#CCCCCC"> 
                <td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Model 
                            Description</font></strong></td>
                <td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Quantity</font></strong></td>
                <td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Unit 
                            Price</font></strong></td>
                <td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Total</font></strong></td>
            </tr>
            <jsp:useBean id="cart" scope="session" class="Cart.CartBean"/>
            <c:if test="${cart.lineItemCount==0}">
                <tr>
                    <td colspan="4"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">- Cart is currently empty -<br/>
                </tr>
            </c:if>
            <c:forEach var="cartItem" items="${cart.cartItems}" varStatus="counter"> 
                <form name="item" method="POST" action="CartController">
                    <tr> 
                        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><c:out value="${cartItem.partNumber}"/></b><br/>
                                <c:out value="${cartItem.modelDescription}"/></font></td>
                        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type='hidden' name='itemIndex' value='<c:out value="${counter.count}"/>'><input type='text' name="quantity" value='<c:out value="${cartItem.quantity}"/>' size='2'> <input type="submit" name="action" value="Update">
                                <input type="submit" name="action" value="Delete"></font></td>
                        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">$<c:out value="${cartItem.unitCost}"/></font></td>
                        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">$<c:out value="${cartItem.totalCost}"/></font></td>
                    </tr>
                </form>
            </c:forEach> 

            <tr> 
                <td colspan="2"> </td>
                <td> </td>
                <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Subtotal: $<c:out value="${cart.orderTotal}"/></font></td>
            </tr>
        </table>
    </body>
</html>

Cart.CartBean

package Cart;

import Cart.CartItemBean;

import java.util.ArrayList;

public class CartBean {

private ArrayList alCartItems = new ArrayList();
private double dblOrderTotal;
int lineItemCount = alCartItems.size();

public int getLineItemCount() {
    return lineItemCount;
}

public void deleteCartItem(String strItemIndex) {

    int iItemIndex = 0;
    try {
        iItemIndex = Integer.parseInt(strItemIndex);
        alCartItems.remove(iItemIndex - 1);
        calculateOrderTotal();
    } catch (NumberFormatException nfe) {
        System.out.println("Error while deleting cart item: " + nfe.getMessage());
        nfe.printStackTrace();
    }
}

public void updateCartItem(String strItemIndex, String strQuantity) {
    double dblTotalCost = 0.0;
    double dblUnitCost = 0.0;
    int iQuantity = 0;
    int iItemIndex = 0;
    CartItemBean cartItem = null;
    try {
        iItemIndex = Integer.parseInt(strItemIndex);
        iQuantity = Integer.parseInt(strQuantity);
        if (iQuantity > 0) {
            cartItem = (CartItemBean) alCartItems.get(iItemIndex - 1);
            dblUnitCost = cartItem.getUnitCost();
            dblTotalCost = dblUnitCost * iQuantity;
            cartItem.setQuantity(iQuantity);
            cartItem.setTotalCost(dblTotalCost);
            calculateOrderTotal();
        }
    } catch (NumberFormatException nfe) {
        System.out.println("Error while updating cart: " + nfe.getMessage());
        nfe.printStackTrace();
    }

}

public void addCartItem(int strModelNo, String strDescription,
        String strUnitCost, String strQuantity) {
    double dblTotalCost = 0.0;
    double dblUnitCost = 0.0;
    int iQuantity = 0;
    CartItemBean cartItem = new CartItemBean();
    try {
        dblUnitCost = Double.parseDouble(strUnitCost);
        iQuantity = Integer.parseInt(strQuantity);
        if (iQuantity > 0) {
            dblTotalCost = dblUnitCost * iQuantity;
            cartItem.setIdNumber(strModelNo);
            cartItem.setTitle(strDescription);
            cartItem.setUnitCost(dblUnitCost);
            cartItem.setQuantity(iQuantity);
            cartItem.setTotalCost(dblTotalCost);
            alCartItems.add(cartItem);
            calculateOrderTotal();
        }

    } catch (NumberFormatException nfe) {
        System.out.println("Error while parsing from String to primitive types: " + nfe.getMessage());
        nfe.printStackTrace();
    }
}

public void addCartItem(CartItemBean cartItem) {
    alCartItems.add(cartItem);
}

public CartItemBean getCartItem(int iItemIndex) {
    CartItemBean cartItem = null;
    if (alCartItems.size() > iItemIndex) {
        cartItem = (CartItemBean) alCartItems.get(iItemIndex);
    }
    return cartItem;
}

public ArrayList getCartItems() {
    return alCartItems;
}

public void setCartItems(ArrayList alCartItems) {
    this.alCartItems = alCartItems;
}

public double getOrderTotal() {
    return dblOrderTotal;
}

public void setOrderTotal(double dblOrderTotal) {
    this.dblOrderTotal = dblOrderTotal;
}

protected void calculateOrderTotal() {
    double dblTotal = 0;
    for (int counter = 0; counter < alCartItems.size(); counter++) {
        CartItemBean cartItem = (CartItemBean) alCartItems.get(counter);
        dblTotal += cartItem.getTotalCost();

    }
    setOrderTotal(dblTotal);
}

}

Cart.CartItemBean

package Cart;

public class CartItemBean {

public int IdNumber;
private String Title;
private String Image;
private double dblUnitCost;
private int iQuantity;
private double dblTotalCost;

public int getIdNumber() {

    return IdNumber;
}

public void setIdNumber(int IdNumber) {
    this.IdNumber = IdNumber;
}

public String getImage() {
    return Image;
}

public void setImage(String Image) {
    this.Image = Image;
}

public String getTitle() {
    return Title;
}

public void setTitle(String Title) {
    this.Title = Title;
}

public double getUnitCost() {
    return dblUnitCost;
}

public void setUnitCost(double dblUnitCost) {
    this.dblUnitCost = dblUnitCost;
}

public int getQuantity() {
    return iQuantity;
}

public void setQuantity(int quantity) {
    iQuantity = quantity;
}

public double getTotalCost() {
    return dblTotalCost;
}

public void setTotalCost(double dblTotalCost) {
    this.dblTotalCost = dblTotalCost;
}

}

非常感谢任何帮助

0 个答案:

没有答案