Spring重定向的两种方式
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封装。
相关推荐
服务器端攻城师 2020-05-04
咻咻ing 2020-01-11
bestallen 2019-12-07
朱培知浅ZLH 2020-11-16
Junzizhiai 2020-10-10
zhangbingb 2020-09-21
ROES 2020-08-17
ningningmingming 2020-07-28
Jiajinjin 2020-07-27
懒人的小窝 2020-07-04
wykpaopao 2020-06-28
lishaokang 2020-06-12
Greatemperor 2020-06-10
谢育政 2020-05-27
wanggongzhen 2020-05-26
ITlover00 2020-05-07
zhongcanw 2020-05-08
DAV数据库 2020-05-07
ningningmingming 2020-05-01