重定向:
// 使用response.sendRedirect重定向
public void hello(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect("/");
}
// 使用redirect:xxx重定向
public String hello(HttpServletRequest request, HttpServletResponse response) throws IOException {
return "redirect:http://www.hao123.com";
}
public RedirectView hello(HttpServletRequest request, HttpServletResponse response) throws IOException {
RedirectView redirectView = new RedirectView();
redirectView.setUrl("http://www.qq.com");
return redirectView;
}
转发:
//使用RequestDispatcher进行转发
public void hello(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
request.getRequestDispatcher("index").forward(request,response);
}
网友评论