aspose file tools*
The moose likes Servlets and the fly likes sendRedirect method of HttpServiceResponse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect method of HttpServiceResponse" Watch "sendRedirect method of HttpServiceResponse" New topic
Author

sendRedirect method of HttpServiceResponse

bob walker
Greenhorn

Joined: Feb 20, 2001
Posts: 14

Maybe someone can shed some light on this subject.
I'm in the service method of my servlet.
The sample code looks like this:
if (request.getSession(false) == null)
response.sendRedirect(myURL);
// code continues below.
Now, this works but my question is: Would the method call
not return and continue executing the remainder of the service
method?
I see the reDirect happening but I'm curious if its servlet
engine implementation specific whether it returns or not.
I can't seem to find an answer in the O'reilly servlet book.
Bhupinder Dhillon
Ranch Hand

Joined: Oct 12, 2000
Posts: 124
You need to explicitly return from the method after the redirect. BTW, why are you overriding the service method??
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

I'm not sure about the specification.
Running on Tomcat it appears that the code after the redirect DOES run.
I determined this by sending a redirect and then connecting and executing an update in a database.
The redirected page comes up and the update was made.
This makes the most sense for flexibility of programming, at least to me.


!_I_Know_Kung_Fu_!
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Yes - Java code is java code - the virtual machine doesn't know anything about the fact you are running a servlet. The rest of the method will be executed unless you return. However, the response will have been committed, so you cannot change anything from the standpoint of the client. The browser has already received the redirect.
------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendRedirect method of HttpServiceResponse
 
Similar Threads
Another q from mock
JSP problem.
Pizza and Servlets
logs filled with exceptions in Solaris
Confused with flush() behavior