Explain how to perform browser redirection from a JSP page

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
20 EJB Interview Questions and Answers - Freshers, Experienced
EJB interview questions and answers, EJB interview FAQ - In this series, we have covered all about EJB and answered the questions that might be asked during an interview
Describe EJB architecture
EJB architecture - The EJB architecture is an extension of Web architecture. It has an additional tier..
EJB - Services that the EJB container offers to the application developer
Services that the EJB container offers - Component Pooling : An EJB component is a server component that provides methods with business logic in distributed applications...
Post your comment