Search code examples
springhibernatejsp-tags

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


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


Solution

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