Spring mvc重定向
两种实现方式:
1、response的重定向
response.setContentType("text/html;charset=UTF-8");
String url = "searchSmallmajorByName.action?parentId="+parentId+"&searchSmallmajorName="+searchName);
response.getWriter().println("<script>");
response.getWriter().println("window.location.href='"+url+"'");
response.getWriter().println("</script>");
2、spring mvc中的ModelAndView
@RequestMapping(value="/common/deleteSmallmajor.action")
public ModelAndView deleteSmallmajor(HttpServletRequest request,
HttpServletResponse response) throws Exception{
//.....
ModelMap mmap = new ModelMap();
mmap.addAttribute("parentId", parentId);
mmap.addAttribute("searchSmallmajorName",searchName);
mmap.addAttribute("page", this.getPageForDelete(params[1],resultCount));
return new ModelAndView("redirect:/common/searchSmallmajorByName.action",mmap);
}
ModelAndView对象作为返回值
第一个参数,我们使用redirect:作为前缀,后面跟随重定向的路径.
第二个参数就是传递的参数,我们用ModelMap封装。