Java-Servlet重定向

本文介绍Servlet中的重定向, 重定向中会自动携带Cookie。

Get

1
2
3
public static void doGetRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException{
response.sendRedirect(url);
}

Post

1
2
3
4
public static void doPostRedirect(HttpServletRequest request, HttpServletResponse response, String url){
response.setStatus(307);
response.addHeader("Location",url);
}