最近在spring mvc中遇到了如何实现页面跳转的问题.比如在页面A中的提交按钮用户提交后,需要重定向到另外一个新的页面,并且有可能要把一些参数带
过去.
这其实在实现中有两个方法
1 在controller中实现redirect,可以使用sendRedirect()方法,然后返回
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
{
........
response.sendRedirect("photohouxuandetail.do?pid="+pid);
return null;
}
2 还可以用redirect来实现,这样viewResolver认为是重定向操作,不再渲染该视图了,而是直接向客户端发出redirect响应
return new ModelAndView("redirect:photohouxuandetail.do?pid="+pid);
过去.
这其实在实现中有两个方法
1 在controller中实现redirect,可以使用sendRedirect()方法,然后返回
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
{
........
response.sendRedirect("photohouxuandetail.do?pid="+pid);
return null;
}
2 还可以用redirect来实现,这样viewResolver认为是重定向操作,不再渲染该视图了,而是直接向客户端发出redirect响应
return new ModelAndView("redirect:photohouxuandetail.do?pid="+pid);
SpringMVC页面跳转
本文介绍了在SpringMVC框架中实现页面跳转的方法,包括使用response.sendRedirect进行重定向及利用ModelAndView对象指定重定向视图的方式。
1154

被折叠的 条评论
为什么被折叠?



