【问题标题】:HTTP Status 500-Exception occuered in JSP :JSP 中发生 HTTP 状态 500-异常:
【发布时间】:2015-05-26 03:58:31
【问题描述】:

我不明白为什么我的 JSP 中出现以下错误。我的控制器正在相应地工作,即它正确返回列表。

Controller.java //这是jsp的控制器 包 com.packt.webstore.controller;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;

     import com.packt.webstore.ServiceInterface.CustomerService;


   @Controller
   public class CustomerController {
   @Autowired
   private CustomerService customerService;
       @RequestMapping("/customer")
          public String List(Model model){

model.addAttribute("customers",customerService.getAllCustomers());
return "customer" ;
}

}

Customer.jsp /这是在我使用 JSTL-core taglib uri 的控制器之后调用的 jsp/

<section class="container">
  <div class="row">
   <c:forEach items="${customers}" var="customer"> 
      <div class="col-sm-6 col-md-3" style="padding-bottom: 15px">
        <div class="thumbnail">
          <div class="caption">
          <p>${customer.CustomerName}</p>
            <h3>${customer.CustomerID}</h3>
             <p>Number of products Ordered ${customer.noOfOrderMade}</p>
          </div>
        </div>
      </div>
    </c:forEach> 
  </div>
</section>

【问题讨论】:

  • 验证变量名可能不正确,还要在 IDE 控制台选项卡中查找异常堆栈跟踪。
  • @Rembo 谢谢。**我通过使用正确的 java 编码约定解决了我的问题,即我用 customer.customerName 替换了 customer.CustomerName。**

标签: jsp spring-mvc jstl jsp-tags


【解决方案1】:

根据 Java bean 约定,您应该在 EL 中调用 customer.customerName 而不是 customer.CustomerName。

有一个如下的 setter 和 getter。

private String customerName;

public String getCustomerName(){
  return customerName ;
}
public Void setCustomerName(String customerName){
  this.customerName = customerName ;
}

如果它仍然不起作用,您可能正在做更多的事情,同时检索 customerName,就像它是一个 JPA 实体等等。

【讨论】:

  • 谢谢。**我通过使用正确的 java 编码约定解决了我的问题,即我用 customer.customerName 替换了 customer.CustomerName。**
  • 最受欢迎,它不仅仅是一个约定,它就像 customerName 被转换为 getCustomerName()
猜你喜欢
  • 2014-04-22
  • 2013-10-07
  • 1970-01-01
  • 2014-07-29
  • 2013-08-26
相关资源
最近更新 更多