JSP Redirect: In JSP Redirect URL is changed and it is slower than JSP Forward.
JSP Redirect Example:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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> <% response.sendRedirect("http://www.apekshit.com"); %> </body> </html>
When the above JSP run on the server, it redirects to www.apekshit.com. If you notice the URL bar, it is changed to www.apekshit.com
It is a 2 step process:
Step 1: JSP Container recives the request for current JSP. It compiles and run the JSP. During execution, it finds the redirect for new resource.
Step 2: It redirects to the new resource.
During these 2 steps, URL is changed as it is considered as a completlye new reqest.
JSP Redirect is slower than JSP forward where JSP container internally forwards the request to new resouce and URL remains intact, hence user does not know about request forwarding.