HttpServlet请求重定向

时间:2023-12-23 14:53:44

方法一:

    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("------- come here -------");
response.setStatus();
response.setHeader("Location", "/day0106/servlet/demo2"); }

方法二:

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.sendRedirect("/day0106/servlet/demo1");
}