Discussions
Web tier: servlets, JSP, Web frameworks: Difference request.forward() and response.sendRedirect .
-
Difference request.forward() and response.sendRedirect . (16 messages)
- Posted by: Kamesh Kiran Mantha Sarvepalli
- Posted on: August 24 2000 03:40 EDT
What exactly is the difference between request.forward() and response.sendRedirect ?
Is there a problem in managing sessions while using response.sendRedirect ?
Threaded Messages (16)
- Difference request.forward() and response.sendRedirect . by Kapil Israni on August 24 2000 09:25 EDT
- Difference request.forward() and response.sendRedirect . by Kamesh Kiran Mantha Sarvepalli on August 24 2000 13:43 EDT
-
Difference request.forward() and response.sendRedirect . by manikandan chandrasekaran on August 24 2000 02:44 EDT
-
Difference request.forward() and response.sendRedirect . by praful c on February 06 2004 11:38 EST
- Difference request.forward() and response.sendRedirect . by praful c on February 06 2004 11:41 EST
-
Difference request.forward() and response.sendRedirect . by praful c on February 06 2004 11:38 EST
-
Difference request.forward() and response.sendRedirect . by Kapil Israni on August 26 2000 08:56 EDT
- Re: Difference request.forward() and response.sendRedirect . by J Dev on February 06 2009 01:06 EST
-
Difference request.forward() and response.sendRedirect . by mahender parvathoju on February 03 2006 06:44 EST
-
session gets expired when we use response.sendRedirect by Priya Rengarajan on February 19 2006 08:52 EST
- I also am losing the session after response.sendRedirect by Brett Kurth on July 03 2006 03:41 EDT
-
session gets expired when we use response.sendRedirect by Priya Rengarajan on February 19 2006 08:52 EST
-
Difference request.forward() and response.sendRedirect . by manikandan chandrasekaran on August 24 2000 02:44 EDT
- Difference request.forward() and response.sendRedirect . by Kamesh Kiran Mantha Sarvepalli on August 24 2000 13:43 EDT
- Difference request.forward() and response.sendRedirect . by Suryanarayana Murthy on August 25 2000 14:57 EDT
- difference between forward and sendRedirect by jagjeet singh on June 19 2007 00:29 EDT
- Forwarding Request Vs Re-Directing URL by jay patel on January 31 2008 13:01 EST
- Forwarding Request Vs Re-Directing URL by Nagkiran CN on July 12 2011 07:09 EDT
- Forwarding Request Vs Re-Directing URL by jay patel on January 31 2008 13:01 EST
- Difference request.forward() and response.sendRedirect . by Duce Bigelow on April 09 2010 05:41 EDT
- Thanks by cristian primavara on April 13 2010 10:09 EDT
-
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: Kapil Israni
- Posted on: August 24 2000 09:25 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
i suppose u r talking bout requestDispatcher.forward() here.
well basically both method calls redirect u to new resource/page/servlet.
the difference between the two is that sendRedirect always sends a header back to the client/browser. this header then contains the resource(page/servlet) which u wanted to be redirected. the browser uses this header to make another fresh request. thus sendRedirect has a overhead as to the extra remort trip being incurred. its like any other Http request being generated by ur browser. the advantage is that u can point to any resource(whether on the same domain or some other domain). for eg if sendRedirect was called at www.mydomain.com then it can also be used to redirect a call to a resource on www.theserverside.com.
where as in case of forward() call, the above is not true. resources from the server, where the fwd. call was made, can only be requested for. but the major diff between the two is that forward just routes the request to the new resources which u specify in ur forward call. that means this route is made by the servlet engine at the server level only. no headers r sent to the browser which makes this very eficient. also the request and response objects remain the same both from where the forward call was made and the resource which was called.
i hope i have hit ur question right. -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: Kamesh Kiran Mantha Sarvepalli
- Posted on: August 24 2000 13:43 EDT
- in response to Kapil Israni
Thanks Kapil,
Well, u have answered part of my question actually.
The second part of my question is that whether I'd face a problem in maintaining the session for a user if I use response.sendRedirect. Is there a possibility for the session to be lost ? If so, why ?
Kiran. -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: manikandan chandrasekaran
- Posted on: August 24 2000 14:44 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
This question has been answered already,check the archives.
regards
mani -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: praful c
- Posted on: February 06 2004 11:38 EST
- in response to manikandan chandrasekaran
HI, i tried searching the archives, for the answer on session loss.
Even i want to know what happens to the session when a response.sendredirect() is done.
In my case i have a Task.jsp which is a pop up (window.open()) , on click of a "OK" button, the same Task.jsp is called but then the page shows an error saying that" Your Session is not valid or event is not passed retry after login in again ".
While debbuging i find that the session.getValue(XXX) are null, even the request.getParameter(XXX) are null ( fine request is understandable, but session also )
but this is working fine when i use https protocol.
Please help.
thanks
Praful -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: praful c
- Posted on: February 06 2004 11:41 EST
- in response to praful c
forgot to mention, i'm using response.sendredirect(Task.jsp?.......)
while redirecting it.
thx.
C.Praful -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: Kapil Israni
- Posted on: August 26 2000 08:56 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
nope, theres no chance of session being lost. no way -
Re: Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: J Dev
- Posted on: February 06 2009 01:06 EST
- in response to Kapil Israni
nope, theres no chance of session being lost. no way
This is not correct, you will have to use encodeRedirectURL() when using response.serndRedirect(). otherwise URL rewriting cannot be used with browsers which do not support cookies. ans session will be lost if session is maintained using url rewriting. Response.sendRedirect example -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: mahender parvathoju
- Posted on: February 03 2006 18:44 EST
- in response to Kamesh Kiran Mantha Sarvepalli
No, not all. Session object live as the browser not colsed, session timed expire,session invalidte -
session gets expired when we use response.sendRedirect[ Go to top ]
- Posted by: Priya Rengarajan
- Posted on: February 19 2006 08:52 EST
- in response to mahender parvathoju
Hi,
I'm also facing the same problem.In my case,the request from the webserver present in India is redirected to teh EMS server present in USA.For that I'm using response.sendRediect().But the session gets expired.I tried using session.getId() to get the session of both the pages,they different.
Any one have solution for this?
Thanks in advance
cheers,
Priya -
I also am losing the session after response.sendRedirect[ Go to top ]
- Posted by: Brett Kurth
- Posted on: July 03 2006 15:41 EDT
- in response to Priya Rengarajan
this appears to only happen on windows 2000, when my code runs a response.sendRedirect(url) it crashes because immediatly after I log the the session id has changed and the session variables are gone. has anyone figured this out yet? -
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: Suryanarayana Murthy
- Posted on: August 25 2000 14:57 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
I think the main difference is in response.sendRedirect() you need to give absolute path of the url and also request and response objects will be passed automatically to the new page. But in the case of forward method, you need to explicitly send the request and response objects to the new page explicitly. Hope I answered your question.
Murthy -
difference between forward and sendRedirect[ Go to top ]
- Posted by: jagjeet singh
- Posted on: June 19 2007 00:29 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
when you invoke a forward request, the request is sent to the another resource on the server, without the client being informed that the another resource is going to process the request. this process occurs completely within the web-container. when a sendRedirect method is invoked, it cause the web-container to return to the web browser indicating that thenew URL should be requested. because the browser issues a new request the object that is stored as a request attributes will be lost before the redirect occurs. this extra process make redirect slower than forward. -
Forwarding Request Vs Re-Directing URL[ Go to top ]
- Posted by: jay patel
- Posted on: January 31 2008 13:01 EST
- in response to jagjeet singh
Request Forwarding: Both request parameter and session is saved URL redirect: It's a brand new request and browser cookie will be saved...you should be able to get the cookie and can retrive the session related data at the server side.( You can store session data in memory or in database at server side....but what you need is the COOKIE..and COOKIE is not lost by URL redirect!) Think like this: Forwarding the Request and Re-Directing URL are two totally different animal. Your server gets the request from the browser..job of server is to send back the response. How how that response is generated is totally up to your server..you can process that request in one servlet or can process the same request using multiple sevlet...To process request using multiple servlet, you need to pass the request to another servlet...and ofcouse we do not want to loose the parameters/data set into the request otherwise that request does not make sense anymore.....This is all request forwarding!...Request forwarding is done during one HTTP request-response cycle..Once you return the response, you are done! Now, In the response, you can tell your browser to do URL redirect to any other URL..this is HTTP header thing and browser will interprete the HTTP header and will send brand new request... -
Forwarding Request Vs Re-Directing URL[ Go to top ]
- Posted by: Nagkiran CN
- Posted on: July 12 2011 07:09 EDT
- in response to jay patel
I am using redirect option to send the request from my application A to a totally different application B. Once I am getting response back from application B, I need to update my database. In this situation, I need to know how to get the application A's session object to does the database action. Is this something possible, OR do I need to re-initiate application A's session object again.
-
Difference request.forward() and response.sendRedirect .[ Go to top ]
- Posted by: Duce Bigelow
- Posted on: April 09 2010 05:41 EDT
- in response to Kamesh Kiran Mantha Sarvepalli
See this servlet redirect example It explains what is the difference between redirect and forward -
Thanks[ Go to top ]
- Posted by: cristian primavara
- Posted on: April 13 2010 10:09 EDT
- in response to Kamesh Kiran Mantha Sarvepalli