The largest Interview Solution Library on the web

« Previous | 1 | 2 | 3 | Next »

JSP - Page Redirection

Page redirection is generally used when a document moves to a new location and we need to send the client to this new location or may be because of load balancing, or for simple randomization.

The simplest way of redirecting a request to another page is using method sendRedirect() of response object. Following is the signature of this method:

public void response.sendRedirect(String location)
throws IOException

This method sends back the response to the browser along with the status code and new page location. You can also use setStatus() and setHeader() methods together to achieve the same redirection:

String site = "" ;
response.setHeader("Location", site);


This example shows how a JSP performs page redirection to an another location:

<%@ page import="*,java.util.*" %>
<title>Page Redirection</title>
<h1>Page Redirection</h1>
// New location to be redirected
String site = new String("");
response.setHeader("Location", site);

Now let us put above code in PageRedirect.jsp and call this JSP using URL
« Previous | 1 | 2 | 3 | Next »

copyright © 2014 - all rights riserved by