setViewName()方法是ModelAndView类的方法,含义是设置View的名字(名字是String类),这个方法的参数有如下三种常见形式:
@RequestMapping("/dologin")
public ModelAndView dologin(HttpServletRequest request, User user) {
User us1 = uss.getUserByName(user.getSrName());
ModelAndView mav = new ModelAndView();
//mav.setViewName("login/login"); //定位到WEB-INF内的jsp
mav.setViewName("redirect:/shuang.jsp"); //定位到WEB-INF外的jsp
//mav.setViewName("redirect:/eli.html"); //定位到@Controller中的方法
if (us1 == null) {
mav.addObject("errorMsg", "用户名不存在");
} else if (!us1.getSrPwd().equals(user.getSrPwd())) {
mav.addObject("errorMsg", "密码不正确");
} else {
setSessionUser(request,us1);
String toUrl = (String)request.getSession().getAttribute(StaticPublic.LOGIN_TO_URL);
request.getSession().removeAttribute(StaticPublic.LOGIN_TO_URL);
if(StringUtils.isEmpty(toUrl)){
toUrl = "public";
}
mav.setViewName(toUrl);
}
return mav;
}