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

ReequestDispatcher include()

Robin M

Joined: Jul 01, 2002
Posts: 9
Running on Websphere 3.5.4 the following code....
for (int i = 0; i < controllers.length; i ++) {
rd = getServletContext().getNamedDispatcher(controllers[i]);
if (rd == null) {
throw new ServletException("Controller " + controllers[i] + " does not exist");
} else {
log("Including Cont Servlet : " + controllers[i]);
log("Point 3a : " + response.isCommitted());
rd.include(request, response);
log("Point 3b : " + response.isCommitted());
Can anyone please tell me why the response is commited at point 3b? This should not be so, and indeed isn't when run under tomcat 4.0.
Furthermore, extract from javadocs indicates....
Includes the content of a resource (servlet, JSP page, HTML file) in the response. In essence, this method enables programmatic server-side includes.
The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
I am includind a servlet DoNothingServlet that does absolutely nothing and even if it was it shouldn't be altering the headers as the above Servlet javadoc indicates....
This is preventing me from later forwarding to a JPS page, as it stated the response is already commited. anyone got any ideas if I'm doing anything wrong...
I have used this design successfully in Tomcat 4.0 for some time.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I don't realy understand what you are trying to accomplish, but it looks like a buffer problem. The default buffer size is supposed to be 8k, but from my experience IBM tend to do whatever they want.
I'd guess that in Tomcat you are finding that all of the included output fits in the buffer, but it doesn't in WS. So WS sends the response to the client and therefore commits the response.
As a matter of design, you should try to organise things so you never try to forward after you have started including content - they are incompatable and you can get pages that behave wierdly.
Robin M

Joined: Jul 01, 2002
Posts: 9
Hi Dave,
Thanks for your feedback here.
I have got round the problem another way, a way that I think is actually a lot better as you can dynamically extend the web app without registering new servlets. Here is a link to the article I read if anyone is interested.
A very good way of using MVC in Web App design
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi dave,
from ur post i assume that if the included page size is more than 8k then it would have to commit the response to the client COMPULSORY.
correct me if i'm wrong...
though i will test this myself whenever i get time.
I agree. Here's the link:
subject: ReequestDispatcher include()
It's not a secret anymore!