The server encountered an unexpected condition that prevented it from fulfilling the request

流过昼夜 提交于 2021-01-27 19:15:35

问题


I am trying to display Data from DB.But Shows error as

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>"

MY 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>

My Controller

public ModelAndView productDtails(@PathVariable int id)
{   
ModelAndView model=new ModelAndView("Detail");
model.addObject("prdt",pd.getById(id));
return model;
}

My DAO IMpl

public Product getById(int id) 
{   
Session session=sessionFactory.openSession();
Product p=(Product) session.get(Product.class, id);
session.close();
return p;
}

Any Idea????


回答1:


You can't iterate over prdt object i.e., you are using forEach tag and prdt is not a List object, so to solve the issue simply remove <c:forEach var="x" items="${prdt}"> or else you need to return a list object from your Contoller.

Your JSP looks as below (after removing <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>



回答2:


My issue was resolved by adding the below in the model

    [AllowHtml]
    public string Description { get; set; }

C# MVC for POST



来源:https://stackoverflow.com/questions/43077139/the-server-encountered-an-unexpected-condition-that-prevented-it-from-fulfilling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!