Friday, March 13, 2009

How do I perform browser redirection from a JSP page? (JSP)

Question :How do I perform browser redirection from a JSP page? (JSP)
Answer :You can use the response implicit object to redirect the browser to a
different resource, as:
response.sendRedirect("http://www.foo.com/path/error.html");
You can also physically alter the Location HTTP header attribute, as shown
below:
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/index.html";
response.setHeader("Location",newLocn);
%>
You can also use the: Also note
that you can only use this before any output has been sent to the client. I
beleve this is the case with the response.sendRedirect() method as well.
If you want to pass any paramateres then you can pass using page="/servlet/login">
>

No comments: