前言
orderItems一个javaBean中内置对象。
以下是报错信息:
java.lang.NumberFormatException: For input string: "orderItems"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at javax.el.ListELResolver.coerce(ListELResolver.java:157)
at javax.el.ListELResolver.getValue(ListELResolver.java:70)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943)
at org.apache.jsp.order_005flist_jsp._jspx_meth_c_005fforEach_005f1(order_005flist_jsp.java:285)
at org.apache.jsp.order_005flist_jsp._jspx_meth_c_005fforEach_005f0(order_005flist_jsp.java:249)
at org.apache.jsp.order_005flist_jsp._jspService(order_005flist_jsp.java:161)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at cn.mldn.web.servlet.ProductServlet.myOrder(ProductServlet.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cn.mldn.web.servlet.BeanServlet.service(BeanServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
java类
private String oid;
private Date ordertime;
private double total;
private int state;//支付状态,1,已支付,2未支付
private String address;
private String name;
private String telephone;
private User user;
List orderItems=new ArrayList();
此报错字面意思为数字格式报错。
1,先检查一下对应的属性类型,是否与封装的数据类型对应。
2,若1,已排除,可参考我的问题所在
此为封装数据代码:
protected void myOrder(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//1,判断是否用户登录
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
if(user==null)
{
//若未空,则需登陆
response.sendRedirect(request.getContextPath()+"/login.jsp");
return;
}
//2.检索出来所有的订单Orders by uid
String uid=user.getUid();
ServiceServlet service=new ServiceServlet();
List<Order> ordersList=null;
try {
ordersList= service.findOrdersByUid(uid);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//3.检索出来所有的订单项,商品项通过 pid相等。然后oid以订单项为主
if(ordersList!=null)
{
for (Order order : ordersList) {
String oid = order.getOid();
try {
List<Map<String, Object>> listMap = service.findOderItemByOid(oid);
for(Map<String, Object> map:listMap)
{
try {
//从map中取出count subtotal 封装到OrderItem中
OrderItem item = new OrderItem();
//item.setCount(Integer.parseInt(map.get("count").toString()));
BeanUtils.populate(item, map);
//从map中取出pimage pname shop_price 封装到Product中
Product product = new Product();
BeanUtils.populate(product, map);
//将product封装到OrderItem
item.setProduct(product);
//将orderitem封装到order中的orderItemList中
order.getOrderItems().add(item);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//将封装好的list集合传递到request域中。
request.setAttribute("ordersList", ordersList);
//跳转到订单信息页
request.getRequestDispatcher("/order_list.jsp").forward(request, response);
}
此为jsp中el代码
<c:forEach items="${ordersList}" var="order">
<tbody>
<tr class="success">
<th colspan="5">订单编号:${order.oid}th>
tr>
<tr class="warning">
<th>图片th>
<th>商品th>
<th>价格th>
<th>数量th>
<th>小计th>
tr>
**********************************
<c:forEach items="${ordersList.orderItems}" var="orderItem">
**出错在此行代码,ordersList集合中无orderItems对象。***************
<tr class="active">
<td width="60" width="40%"><input type="hidden" name="id"
value="22"> <img src="${pageContext.request.contextPath }/${orderItem.product.pimage}" width="70"
height="60">td>
<td width="30%"><a target="_blank"> ${orderItem.product.pname }a>td>
<td width="20%">¥${orderItem.product.shop_price }td>
<td width="10%">${orderItem.count }td>
<td width="15%"><span class="subtotal">¥${orderItem.subtotal }span>td>
tr>
c:forEach>
tbody>
c:forEach>
解决:将jsp中的el代码进行检查,发现ordersList集合中并无orderItems对象,而是通过ordersList下的order中的orderItems。
所以代码改为:
forEach items="${order.orderItems}" var="orderItem">
总结:检查jsp中的el代码,是不是调用错了内置对象
————————————————————上文出自胖胖,转载请附带原文链接
后续更新自学的方法,以及java知识总结
我是哪怕前路坎坷,也不愿负年轻的菜狗,自学之路,共勉