ModelAndView addObject存入值后前台页面el表达式取不到
后台controller
public class UserController extends MultiActionController{
@RequestMapping(params="method=reg")
public ModelAndView reg(String uname){
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
User u = new User();
u.setUname(uname);
mv.addObject(u);
mv.addObject("a", "aaaa");
return mv;
}
}
前台页面
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h1>${requestScope.a}</h1>
<h1>${requestScope.user.uname}</h1>
</body>
</html>
跳转到index页面始终显示${requestScope.a} ${requestScope.user.uname},值却显示不出来
[解决办法]
头部加上<%@ page isELIgnored="false" %>看看
或者直接request.getParameter("a");