我正在尝试显示来自 DB 的数据。但显示错误为
The server encountered an unexpected condition that prevented it from fulfilling the request
异常(exception)
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/pages/Detail.jsp at line 14
11: </head>
12: <body>
13:
14: <c:forEach var="x" items="${prdt}">
15: <table>
16: <img src="resources/Images/${x.id}.png"/>
17: <td>"
我的 JSP
<c:forEach var="x" items="${prdt}">
<table>
<img src="resources/Images/${x.id}.png"/>
<td>
<c:out value="${x.product_Name}"/></td>
<td>
<c:out value="${x.descripction}"/></td>
<td>
<c:out value="${x.price}"/></td>
<td>
<c:out value="${x.mfg_Date}"/>
</td>
</table>
</c:forEach>
我的 Controller
public ModelAndView productDtails(@PathVariable int id)
{
ModelAndView model=new ModelAndView("Detail");
model.addObject("prdt",pd.getById(id));
return model;
}
我的 DAO IMpl
public Product getById(int id)
{
Session session=sessionFactory.openSession();
Product p=(Product) session.get(Product.class, id);
session.close();
return p;
}
任何的想法????
最佳答案
你不能迭代 prdt
对象,即您正在使用 forEach
标签和 prdt
不是 List
对象,所以要解决这个问题,只需删除 <c:forEach var="x" items="${prdt}">
否则你需要返回一个 list
来自 Controller 的对象。
您的 JSP 如下所示(删除 <c:forEach
后):
<table>
<img src="resources/Images/${x.id}.png"/>
<td>
<c:out value="${prdt.product_Name}"/></td>
<td>
<c:out value="${prdt.descripction}"/></td>
<td>
<c:out value="${prdt.price}"/></td>
<td>
<c:out value="${prdt.mfg_Date}"/>
</td>
</table>
关于spring - 服务器遇到了阻止它完成请求的意外情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43077139/