我试图访问存储在List中的Object数组中的每个元素,但每当我尝试通过Model类的索引/属性访问它时,它会抛出异常
[2016/09/06 10:12:19:351 GMT+02:00] 00000049 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/WEB-INF/views/instruction.jsp] in application [SpringMVCHibernate_war]. Exception created : [javax.el.PropertyNotFoundException: Property '0' not found on type java.lang.Integer
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:232)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:209)
at javax.el.BeanELResolver.property(BeanELResolver.java:319)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:89)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
at org.apache.el.parser.AstValue.getValue(AstValue.java:174)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:778)
at com.ibm._jsp._instruction._jspx_meth_c_forEach_1(_instruction.java:133)
at com.ibm._jsp._instruction._jspx_meth_c_forEach_0(_instruction.java:184)
at com.ibm._jsp._instruction._jspx_meth_c_if_0(_instruction.java:227)
at com.ibm._jsp._instruction._jspService(_instruction.java:97)
以下是我的jsp片段:
<c:forEach items="${listPersons}" var="listObj">
<c:forEach items="${listObj}" var="instruction">
<tr>
<td>${instruction[0]}</td>
<td>${instruction[1]}</td>
<td>${instruction[2]}</td>
<td>${instruction[3]}</td>
</tr>
</c:forEach>
</c:forEach>
尝试了以下方式,但得到了相同的javax.el.PropertyNotFoundException:
<c:forEach items="${listPersons}" var="listObj">
<c:forEach items="${listObj}" var="instruction">
<tr>
<td>${instruction.iKey}</td>
<td>${instruction.sProc}</td>
<td>${instruction.bCurrency}</td>
<td>${instruction.wModified}</td>
</tr>
</c:forEach>
</c:forEach>
,其中
model.addAttribute("instruction", new Instruction());
model.addAttribute("listPersons", this.personService.listPersons());
和列表是:
List<Object[]> personsList = session.createSQLQuery("SELECT * FROM MyDB.INSTRUCTION").list();
下面是样本列表输出:
[25258188, SP, IND, 2016-03-16 08:07:11.0]
[25258191, NR, USD, 2016-03-16 08:07:11.0]
答案 0 :(得分:1)
您收到此异常是因为JSP中的指令变量不是数组或列表的类型 它的简单字符串或任何其他类型,尝试了解您的流量并验证天气列表人员是否包含列表内的列表
答案 1 :(得分:1)
试试这个
<c:forEach items="${listPersons}" var="listObj">
<tr>
<td>${listObj[0]}</td>
<td>${listObj[1]}</td>
<td>${listObj[2]}</td>
<td>${listObj[3]}</td>
</tr>
</c:forEach>