Java servlets: how to display a page?
I'm using a Java Servlet to do some work (validate user login, update session values, etc.) and I want to r开发者_如何转开发edirect to an existing JSP page when I'm done. How do I do that?
response.sendRedirect("page.jsp");
also to sendRedirect
take a look at
request.getRequestDispatcher("/foo/foo.jsp").forward(request, response);
redirect is useful then you changed some information (e.g. made a post in the forum) so redirecting will prevent double posting.
Apart from using HttpServletResponse.sendRedirect()
, you can also set the http response header and status code to SC_MOVED_PERMANENTLY (301)
or SC_MOVED_TEMPORARILY (302)
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", "http://www.xxx.yyy/");
精彩评论