当前位置: 代码迷 >> Web前端 >> Spring重定向的两种形式
  详细解决方案

Spring重定向的两种形式

热度:101   发布时间:2012-09-10 11:02:32.0
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封装。

  相关解决方案