結論: 直接用 sendRedirect 就好了.
Redirect
protected void doGet(HttpServletRequest req, HttpServletResponse resp){
resp.sendRedirect("http://www.google.com");
}
Forward
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher("/servlet2");
dispatcher.forward(req, resp);
}
forward() method | sendRedirect() method |
---|---|
The forward() method works at server side. | The sendRedirect() method works at client side. |
It sends the same request and response objects to another servlet. | It always sends a new request. |