最近在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);

相关文章:

  • 2021-09-08
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
猜你喜欢
  • 2022-12-23
  • 2021-10-11
  • 2021-12-14
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案