public void response.sendRedirect(String location) throws IOExceptionThis 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 = "http://www.dineshonjava.com" ;
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
....
JSP Redirect Example:<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JSP Redirect Example</title>
</head>
<body>
<%
String site = "http://www.dineshonjava.com" ;
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
response.sendRedirect(site);
%>
</body>
</html>
When the above JSP run on the server, it redirects to www.dineshonjava.com. If you notice the URL bar, it is changed to www.dineshonjava.com
Labels: JSP