File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes I have no idea why this is happening 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 "I have no idea why this is happening" Watch "I have no idea why this is happening" New topic

I have no idea why this is happening

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
hi all,
i found out something very strange thing abt servlets.i dont know if i am right but anyway....
in one of my servlets, if a particular condition is met i forward the request to a certain jsp page

and if the condition is not met i do some other processing in the servlet i realized that the request comes back to this servlet after the jsp page execution is over.till now i believed that once request has been forwarded, the control passes on to the called servlet/jsp page.
am i right?if i am right what should i do so that the request doesn't come back to the calling servlet.i know i can use the else condition.but in my case there are situations where i cannot use else condition
any help would be greatly appreciated.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12675
According to the API, when the call to forward returns, the response output stream should be flushed and closed, so your calling servlet should not be able to write anything more. However, the thread that calls forward does return to the calling method, so you can do other stuff.

author of:

Java Resources at
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
thanks bill for your response.
is there anyway i can prevent the execution of the code after the forward statement.can i use something like exit just after the forward it advisable?
I agree. Here's the link:
subject: I have no idea why this is happening
Similar Threads
If any exception happens in the server code error message would be displayed
Session and RequestDispatcher question
Servlet causing: java.sql.SQLException: Connection closed
How do i use requestDispatcher.forward to forward to my struts action servlet?