FAQ

Java

JSP

Servlet


Advertisement



Does the RequestDispatcher.forward/include method return?

RequestDispatcher defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name.

Actually the RequestDispatcher.forward() and RequestDispatcher.include() are just method calls to the other JSP/servlet.

The control (flow of program)is indeed returned to the line after this line once it completes. The body of the code after the forward will still be processed and any unhandled exceptions will be thrown to requesting servlet.

The control is absolutely returned. However, there are some restrictions on what you can do afterwards -- in particular, you can no longer write to the response (it is assumed that the forwarded-to servlet took care of that already), so the only prudent thing to do is "return".


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |