wood burning stoves
The moose likes Servlets and the fly likes working of response.sendRedirect() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "working of response.sendRedirect()" Watch "working of response.sendRedirect()" New topic

working of response.sendRedirect()


Joined: Jun 26, 2001
Posts: 1
i want to know how does response.sendRedirect work ?
example :
This is my simple jsp
<%@ language="java" import="java.lang.*,java.io.*,java.util.*"%>
<% response.sendRedirect("test1.jsp");
System.out.println("1 line");
System.out.println("2 line");
System.out.println("3 line");
System.out.println("4 line");
System.out.println("5 line");
This is the test1.jsp
System.out.println("test1 1");
System.out.println("test1 2");
System.out.println("test1 3");

<BODY> this is hushann from cst
when I run the first jsp ie test.jsp it redirects the response to the test1.jsp
The sequence in which the System.out are printed in my system is
first of test.jsp
and then of test1.jsp
my query was.
1. Is there any logical sequence in which the execution is carried out?
2. Does the server fork another thread to carry out the redirection while it proceeds with the calling jsp ?
3. Should the response at all return to the calling jsp after redirection ?
Thanx in advance
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
JavaRanch has a Naming Policy In order to be entered in the drawing for the book giveaway, your name must meet this policy. Please reregister with a correct name.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Send redirect sends a message to the client (the browser) to redirect to a different page. The sequence is
1)client sends request 1 to server
2) server sends redirect message to client
3-1) server continues processing page
3-2) client sends request for redirect page to server
3-3) server processes request 2 in its own thread
After the server sends the redirect request to the client, there are two requests on the server each running its own thread. In the vast majority of cases, the server will finish processing the first request before it starts handling the second. However, its possible that some/all of the second request will get processed before the first request/thread completes.
Prateek Negi

Joined: Jun 26, 2001
Posts: 2
Thanx Avery Gross for the answer . It did clearly answer all me queries
And Sorry Carl Trusiak for the mistake in the UserName . I have changed as adviced by you
I agree. Here's the link: http://aspose.com/file-tools
subject: working of response.sendRedirect()
It's not a secret anymore!