Explain how to perform browser redirection from a JSP page?
The response implicit objects can be used in the following manner:
response.sendRedirect(http://www.abc.com/path/error.html);
The Location HTTP header attribute can be physically altered, as shown below:
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/index.html";
response.setHeader("Location",newLocn);
%>
You can also use the: <jsp:forward page="/newpage.jsp" />
Note: This can be used only before any output has been sent to the client. Same is the case with the response.sendRedirect() method as well. If you want to pass any paramateres then you can pass using <jsp:forward page="/servlet/login"> <jsp:param name="username" value="jsmith" /> </jsp:forward>
What are the ways to pass control from one JSP page to another?
This can be done in two ways:
1. The RequestDispatcher object‘s forward method to pass the control.
2. The response.sendRedirect method