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.
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.
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>