ModelAndView不向jsp视图返回任何数据



我正在使用Spring MVC 3, NetBeans

我有以下模型,

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;

}

这是我的控制器方法

@RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public ModelAndView ShowForm(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("ListApplication"); 
    mav.addObject("apps", marketPlaceService.listApplications());
    return mav;
}

marketPlaceService.listApplications()方法返回列表。这是我的视图

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

从调试中,我看到列表中至少有20条记录,但jsp视图没有显示任何内容。

编辑:有趣的是,这段代码是有效的,

 protected ModelAndView handleRequestInternal(
        HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ModelAndView mav = new ModelAndView("ListApplication");
    mav.addObject("apps", marketPlaceService.listApplications());
    return mav;
}

谁能告诉我原因?

您的<img>标签格式不正确:

<img " src="${item.templateLogo}" border="0" alt="" />
应:

<img src="${item.templateLogo}" border="0" alt="" />

你也有</div></td>后的<img/>标签,不应该在那里。

不确定模板名称,描述和类别,但…也许<img>标记中的错字导致jstl无法正确过滤。

这是我很快找到的答案,

    @RequestMapping(value = "/ListApplication.htm", method = RequestMethod.GET)
public String ShowForm(HttpServletRequest request, ModelMap m) {        
    m.addObject("apps", marketPlaceService.listApplications());
    return "ListApplication";
}

欢迎任何进一步的改进。然而,addObject似乎被弃用了,还有其他选择吗?

相关内容

  • 没有找到相关文章

最新更新