ModelAndView returns no data to jsp views
I am using Spring MVC 3, NetBeans
I have the following model,
public class MarketPlace {
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
private String category;
public String getCategory() {
return category;
}
and this is my controller method,
@RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public ModelAndView ShowForm(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("ListApplication");
mav.addObject("apps", marketPlaceService.listApplications());
return mav;
}
the marketPlaceService.listApplications() method returns List. and here is my view,
<c:forEach items="${apps}" var="item">
<p>Template Name: ${item.templateName}</p>
<p>Description: ${item.description}</p>
<p>Category: ${item.category}</p>
<p><img " src="${item.templateLogo}" border="0" alt="" /></div></td></p>
<br><br>
</c:forEach>
From debugging I see at least 开发者_StackOverflow中文版20 records in the list but the jsp view shows nothing.
Edit: Interestingly, this code is working,
protected ModelAndView handleRequestInternal(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("ListApplication");
mav.addObject("apps", marketPlaceService.listApplications());
return mav;
}
Can anyone tells me the reason.
Your <img>
tag is badly formed:
<img " src="${item.templateLogo}" border="0" alt="" />
Should be:
<img src="${item.templateLogo}" border="0" alt="" />
You also have </div></td>
after the <img/>
tag which shouldn't be there.
Not sure about the template name, description and category though... Maybe the typo in the <img>
tag is causing the jstl to not be filtered correctly.
This is answer that I found so fast,
@RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public String ShowForm(HttpServletRequest request, ModelMap m) {
m.addObject("apps", marketPlaceService.listApplications());
return "ListApplication";
}
Any further improvement is welcome. However, addObject is seems to be deprecated, any alternative?
精彩评论