File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes is forward can call after response generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "is forward can call after response generation" Watch "is forward can call after response generation" New topic

is forward can call after response generation

balakrishna nannaka

Joined: May 08, 2006
Posts: 3
if forward or request dispatcher can call after generating some respone in the servlet which is called
Harpreet Hira
Ranch Hand

Joined: Sep 27, 2001
Posts: 72
What do you mean by generating some response?
You can forward a request to another resource, if you have NOT committed(flushed) response to the browser.

You must be thinking how "committing a response" is different from "generating some response" ?
Generally we take a PrintWriter(out) from response and do out.println() to write something to response. This is NOT committing the response. The response is committed either on calling flush() explicitly, or when the response size increases the buffer size(8KB is default buffer size) or when you service() method completes execution and control goes back to Servlet Container.

So, in a nutshell, if you have NOT flushed the data in a servlet or JSP and NOT exceeded the buffer size you can forward the request to some other resource in the same context.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
It's possible if chunked transmission used.

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I agree. Here's the link:
subject: is forward can call after response generation
It's not a secret anymore!