When I’m done processing in a servlet, and the result is valid, then I need to redirect the response to another JSP page, say welcome.jsp in web content folder. How can I do it?
For example:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
// Some processing code here ...
// How do I redirect to another JSP here when I'm ready?
} catch (Exception e) {
throw new ServletException(e);
}
}
Look at the
HttpServletResponse#sendRedirect(String location)method.Use it as:
Alternatively, look at
HttpServletResponse#setHeader(String name, String value)method.The redirection is set by adding the location header: