日期:2014-05-18  浏览次数:20760 次

JSP页面取不到ModelAndView里面存的值~~
Controller代码:

@RequestMapping(value="selectDepts2.do")
public ModelAndView findDepts2() {
 List<Dept> depts=deptService.getDpets();
 ModelAndView mav=new ModelAndView("dept");
 mav.addObject("depts", depts.get(0));
 return mav;
}


jsp页面 则是直接通过 ${depts}

整个过程都没有报错,只是页面显示出来的就是 "${depts}" 这个字符串。。
网上一直还找不到解答,求各位大侠帮帮看~~谢啦~~!
------解决方案--------------------
先将你的 “depts” 放在controller中某个域对象的属性中(requt.setattribute(“depts”,depts)),然后通过EL表达式获取
------解决方案--------------------
spring的MVC是对Servlet的封装,ModelAndView中addObject应该是对request.setAttribute方法的封装,所以在jsp中如果想以el表达式来读取数据,应该用${requestScope.depts},对应于<%=request.getAttribute("depts")%>
------解决方案--------------------
你先学明白怎么用JSTL标签或者怎么用EL表达式就完事了。