Redirection instructs the client's browser to make a new request to a different URL.
This is commonly used after form submissions or for URL restructuring.
To redirect the request to another page, use the method:
sendRedirect(String)
.
The argument passed to this method can be interpreted as:
You can also specify a redirect path to another domain.
response.sendRedirect("http://www.mtitek.com/mywebapp/formParameters.htm");
The
sendRedirect
method performs the following actions:
-
Clears any existing response content buffer;
-
Sets the response status code to 302 (Found/Moved Temporarily);
-
Adds a "Location" header to the response with the redirection URL provided as the method argument.
You can achieve the same behavior by manually setting the appropriate response headers:
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "http://www.mtitek.com/tutorials/linux/index.php");
However, be aware that any content generated before this code is executed will not be cleared and will still be sent to the client.