<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;"><b>JSP Redirect:</b> In JSP Redirect URL is changed and it is slower than JSP Forward.<br />
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<b><i> sendRedirect()</i></b> of response object. Following is the signature of this method:</p>
<pre class="highlight">public void response.sendRedirect(String location) 
throws IOException 
</pre>
<p>This method sends back the response to the browser along with the status code and new page location. You can also use<i><b> setStatus() and setHeader() </b></i>methods together to achieve the same redirection:</p>
<pre class="highlight">.... 
String site = "https://dineshonjava.com" ; 
response.setStatus(response.SC_MOVED_TEMPORARILY); 
response.setHeader("Location", site); 
.... 
</pre>
<p><b>JSP Redirect Example:</b></p>
<pre class="highlight"><;%@ 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 = "https://dineshonjava.com" ; 
 response.setStatus(response.SC_MOVED_TEMPORARILY); 
 response.setHeader("Location", site); 
 response.sendRedirect(site); 
 
 %>; 
<;/body>; 
<;/html>; 
</pre>
<p>When the above JSP run on the server, it redirects to <b><i>dineshonjava.com</i></b>. If you notice the URL bar, it is changed to<i><b> dineshonjava.com</b></i></p>
<p><b>It is a 2 step process:</b><br />
<b>Step 1:</b> JSP Container receives the request for current JSP. It compiles and run the JSP. During execution, it finds the redirect for new resource.</p>
<p><b>Step 2:</b> It redirects to the new resource.</p>
<p>During these 2 steps, URL is changed as it is considered as a completely new request.</p>
<p>JSP Redirect is slower than JSP forward where JSP container internally forwards the request to new resource and URL remains intact, hence user does not know about request forwarding.</p>
<p>Now let us put above code in <i><b>index.jsp </b></i>and call this JSP using URL <b><i>http://localhost:8080/index/index.jsp</i></b>. This would take you given <i><b>URL https://dineshonjava.com.</b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/09/444.png" border="0" /></div>
<p> ;</p>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/jsp-forward-tag-example/">Previous</a> <;<; || <a href="https://dineshonjava.com/jsp-tutorial-baby-step-to-server-pages/">Index </a>|| >;>;<a href="https://dineshonjava.com/jsp-forward-vs-redirect/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jsp-forward-tag-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/jsp-forward-vs-redirect/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '341'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…