我认为最初的问题很混乱。Spring MVC和请求属性
我有一个HashMap,需要从我想通过Spring Controller发送到视图的数据库收集。我不想把这个HashMap放在model.addAttribute()中,因为Spring Model对象返回一个Map,而我的JSP需要的集合是Collection<Object>
。如果我将我的HashMap.values()设置为request.setAttribute,如果我的方法返回一个String,该如何去调用该请求变量到视图?
@RequestMapping(method = RequestMethod.GET)
public String home(Locale locale, Model model, HttpServletRequest request) {
model.addAttribute("surveys", mySurveys); //this is a map and I need a Collection<Object>
//So I'd like to do this, but how do I get to the "evaluations" object in a view if I'm not dispatching it (like below)??
request.setAttribute("evaluations", mySurveys);
//RequestDispatcher rd = request.getRequestDispatcher("pathToResource");
//rd.forward(request, response);
return "home";
}
编辑:春天标签库不能用于这个特殊的用例。
谢谢。
您使用Spring MVC并且不能使用Spring Taglibs,它是** Spring MVC jar中的** - 为什么不呢? – Xaerxess
我可以使用它,但我使用的TagLib适合我们正在使用的系统的界面。用户期望它看起来有某种特定的方式。 – Robert
因此,如果您使用addAttribute将其添加到模型中,那么您是不是可以使用home.jsp中的$ {surveys}简单地访问它? – digitaljoel