我想在Jsp頁面中使用JSTL打印List對象,但我收到了一些異常。下面是我的應用程序JSTL無法打印對象列表
public class ItemMaster implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1364853156929567630L;
private BigDecimal itemId;
private String itemNumber;
private String description;
private String lifeCyclePhase;
public BigDecimal getItemId() {
return itemId;
}
public void setItemId(BigDecimal itemId) {
this.itemId = itemId;
}
public String getItemNumber() {
return itemNumber;
}
public void setItemNumber(String itemNumber) {
this.itemNumber = itemNumber;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLifeCyclePhase() {
return lifeCyclePhase;
}
public void setLifeCyclePhase(String lifeCyclePhase) {
this.lifeCyclePhase = lifeCyclePhase;
}
下面的模型類是列表
@RequestMapping(value="/searchQuery", method=RequestMethod.POST)
public ModelAndView submitForm(HttpServletRequest request, ModelAndView model) {
String[] listBox1 = request.getParameterValues("selectedright");
List<ItemMaster> lists=itemDao.fetchRecords(listBox1);
model.addObject("queryResult",lists);
model.setViewName("results");
return model;
}
下面的控制器是我的jsp頁面的地方我試圖找回值段
<c:forEach var="queryResult" items="${queryResult}" varStatus="status">
<tr>
<td>${status.index + 1}</td>
<td>${queryResult.itemId}</td>
<td>${queryResult.itemNumber}</td>
<td>${queryResult.description}</td>
<td>${queryResult.lifeCyclePhase}</td>
</tr>
</c:forEach>
我得到的錯誤是
java.lang.NumberFormatException: For input string: "itemId"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
javax.el.ListELResolver.coerce(ListELResolver.java:157)
javax.el.ListELResolver.getValue(ListELResolver.java:70)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
org.apache.el.parser.AstValue.getValue(AstValue.java:167)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:936)
org.apache.jsp.WEB_002dINF.views.results_jsp._jspService(results_jsp.java:145)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
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:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我建議纔去任何進一步閱讀本。你的方法和變量名稱是一團糟。 http://www.oracle.com/technetwork/java/codeconventions-135099.html –
@AlanHay我做了這些更改仍然收到相同的錯誤 –
您無法直接訪問BigDecimal值,因爲您需要用戶jstl格式化程序。請檢查我的回答 –