Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javax.el.PropertyNotFoundException:在类[Others.Customer]上未找到名为[ShoppingBag]的公共静态字段_Java_Jsp - Fatal编程技术网

javax.el.PropertyNotFoundException:在类[Others.Customer]上未找到名为[ShoppingBag]的公共静态字段

javax.el.PropertyNotFoundException:在类[Others.Customer]上未找到名为[ShoppingBag]的公共静态字段,java,jsp,Java,Jsp,我有一个jsp,从中访问名为Customer的JavaBean的shoppingbag属性。但不幸的是,每当我运行jsp时,我都会遇到这个异常 org.apache.jasper.JasperException: org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: No public static field named [ShoppingBag] was found on class [Others.Cu

我有一个jsp,从中访问名为Customer的JavaBean的shoppingbag属性。但不幸的是,每当我运行jsp时,我都会遇到这个异常

org.apache.jasper.JasperException: org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: No public static field named [ShoppingBag] was found on class [Others.Customer]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

javax.el.PropertyNotFoundException: No public static field named [ShoppingBag] was found on class [Others.Customer]
javax.el.StaticFieldELResolver.getValue(StaticFieldELResolver.java:61)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
org.apache.el.parser.AstValue.getValue(AstValue.java:169)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:936)
org.apache.jsp.Header_jsp._jspx_meth_c_005fif_005f0(Header_jsp.java:249)
org.apache.jsp.Header_jsp._jspService(Header_jsp.java:167)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:934)
org.apache.jsp.MainPage_jsp._jspService(MainPage_jsp.java:107)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
这是我的JSP

<li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" >WOMEN <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="AbdulTayyebs?ID=201">Tops </a></li>
        <li><a href="AbdulTayyebs?ID=202">Shirts </a></li>
        <li><a href="AbdulTayyebs?ID=203">Trousers & Jeans </a></li>
        <li><a href="AbdulTayyebs?ID=204">Inner Wears </a></li>
        <li><a href="AbdulTayyebs?ID=205">Leggings</a></li>
      </ul>
    </li>
<li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" >KIDS<span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
      </ul>
    </li>
    <li  role ="presentation" class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" ><span  class="glyphicon glyphicon-shopping-cart" ></span></a>
      <ul class="dropdown-menu" role="menu"> 
          <c:if test="${Customer!=null}">
              <li><a href="Billing.jsp">Shopping Cart <span class="badge">
               ***${Customer.ShoppingBag.Size}***   
                      </span> </a></li>   
          </c:if>
          <c:if test="${Customer==null}">
          <li><a href="Billing.jsp">Shopping Cart <span class="badge">${0}</span> </a></li>
          </c:if>
         </ul>
    </li>
</ul>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <form class="navbar-form navbar-left" role="search" action="AbdulTayyebs?">
    <div class="form-group">
        <input type="text" class="form-control" width="200" placeholder="Search" name="Search">
    </div>
    <button type="submit" class="btn btn-default">Search</button>
  </form>
<ul class="nav navbar-nav navbar-right">  
    <li><a href="#">Contact Us </a></li>
    <c:if test="${Logged == false or Logged==null}">
    <li><a href="Signup.jsp"><span class="glyphicon glyphicon-log-in"></span> Login</a></li></c:if>     
    <c:if test="${Logged!=null}">
    <c:if test="${Logged==true}">
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" >${Customer.getFirstname()}<span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="Profile.jsp"> View Profile </a></li>
        <li><a href="AbdulTayyebs?ViewAddress=true"> Add/Remove Address </a></li>
        <li><a href="ChangePassword.jsp"> Update Password </a></li>
        <li><a href="AbdulTayyebs?GetOrders=true"> My Orders </a></li>
      </ul>
    </li>
    <li><a href="AbdulTayyebs?Action=Logout"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
    </c:if>
    </c:if>
    </ul>
 </div> 
</nav>
  • 搜寻

    这是我们班的顾客

    public class Customer extends User implements java.io.Serializable{
    private String password;
    private ArrayList <PurchaseableItem> ShoppingBag;
    private ArrayList <String> WishList;;
    
    public Customer() {
     super();   
     ShoppingBag=null;
     WishList=null;
    }
    public String getPassword() { return password; }
    
    public ArrayList<String> getWishList() { return WishList; }
    
    public void setWishList(ArrayList<String> WishList) { this.WishList =    WishList; }
    
    public void setPassword(String password) { this.password = password; }
    
    public ArrayList<PurchaseableItem> getShoppingBag(){ return this.ShoppingBag; }
    
    public void setShoppingBag(ArrayList<PurchaseableItem> ShoppingBag) { this.ShoppingBag = ShoppingBag; }
    
    public void AddToShoppingBag(ArrayList<PurchaseableItem> ShoppingBag){
      if(ShoppingBag!=null){
       if(this.ShoppingBag==null){
        this.ShoppingBag = new ArrayList<>();
        }    
       for(PurchaseableItem prc:ShoppingBag)
        this.ShoppingBag.add(prc);
     }
     }
    
     public int TotalItems(){
     return ShoppingBag.size(); 
     }
    }
    
    公共类客户扩展用户实现java.io.Serializable{
    私有字符串密码;
    私人ArrayList购物袋;
    私人ArrayList WishList;;
    公众客户(){
    超级();
    ShoppingBag=null;
    愿望列表=空;
    }
    公共字符串getPassword(){return password;}
    public ArrayList getWishList(){return WishList;}
    public void setWishList(ArrayList WishList){this.WishList=WishList;}
    public void setPassword(字符串密码){this.password=password;}
    public ArrayList getShoppingBag(){返回this.ShoppingBag;}
    public void setShoppingBag(ArrayList ShoppingBag){this.ShoppingBag=ShoppingBag;}
    公共无效添加至购物袋(ArrayList购物袋){
    if(ShoppingBag!=null){
    if(this.ShoppingBag==null){
    this.ShoppingBag=new ArrayList();
    }    
    适用于(可购买项目中国:购物袋)
    此.ShoppingBag.add(中国);
    }
    }
    公共项目{
    返回购物袋。大小();
    }
    }
    

    我无法理解为什么会发生此错误。如果有人能帮我解决这个问题,那将是非常值得赞赏的。

    您不遵守Java命名约定,这是自食其果。它们很简单:

    • 包以小写字母命名。因此包
      Others
      应命名为
      Others
    • 变量(包括字段)是用骆驼式大小写的。因此,
      ShoppingBag
      应该命名为
      ShoppingBag
      ,而
      WishList
      应该命名为
      WishList
    • 方法是CAMELCASE。因此,
      AddToShoppingBag()
      应命名为
      AddToShoppingBag()
    • 当您有一个名为
      getShoppingBag()
      的getter时,相应的bean属性名为
      shoppingBag
      ,而不是
      shoppingBag
      。jspel用于访问bean属性。因此,要从JSP EL调用
      customer.getShoppingBag()
      ,可以使用
      ${customer.shoppingBag}
      ,而不是
      ${customer.shoppingBag}
    • 在这种情况下,页面、请求、会话和应用程序属性的命名类似于局部变量。因此,您永远不应该拥有
      ${Customer}
      ,而应该始终拥有
      ${Customer}

    尊重这些Java约定,一切都会好得多,你的代码会保持一致,你的同事也不会想杀了你。

    你不尊重Java命名约定,这是在自讨苦吃。它们很简单:

    • 包以小写字母命名。因此包
      Others
      应命名为
      Others
    • 变量(包括字段)是用骆驼式大小写的。因此,
      ShoppingBag
      应该命名为
      ShoppingBag
      ,而
      WishList
      应该命名为
      WishList
    • 方法是CAMELCASE。因此,
      AddToShoppingBag()
      应命名为
      AddToShoppingBag()
    • 当您有一个名为
      getShoppingBag()
      的getter时,相应的bean属性名为
      shoppingBag
      ,而不是
      shoppingBag
      。jspel用于访问bean属性。因此,要从JSP EL调用
      customer.getShoppingBag()
      ,可以使用
      ${customer.shoppingBag}
      ,而不是
      ${customer.shoppingBag}
    • 在这种情况下,页面、请求、会话和应用程序属性的命名类似于局部变量。因此,您永远不应该拥有
      ${Customer}
      ,而应该始终拥有
      ${Customer}
    尊重这些Java约定,一切都会好得多,您的代码会保持一致,您的同事也不会想杀了您