springmvc实现转发和重定向

时间:2020-07-12 22:06:29   收藏:0   阅读:82

一、
@RequestMapping("/testVoid")
public String testVoid(HttpServletRequest request){

    //转发方式一
    return "forward:/WEB-INF/pages/success.jsp";  //转发到指定的页面并能获取megs值

    //重定向方式一
    return "redirect:testIndex";   重定向到指定的Action,再跳转到相应的页面,获取不到megs值
}

二、
/**
*
*
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@RequestMapping("/testVoid1")
public void testVoid1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//转发方式二
request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request,response);

    //重定向方式二
    response.sendRedirect(request.getContextPath()+"/account/testIndex"); // 重定向到指定的Action,再跳转到相应的页面,获取不到megs值
    return;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!