IntelliJ Java IDE
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher include throws IllegalStateException? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "RequestDispatcher include throws IllegalStateException?" Watch "RequestDispatcher include throws IllegalStateException?" New topic
Author

RequestDispatcher include throws IllegalStateException?

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
First, note that the Spec (SRV.8.3) mentions about target servlet. But then the API mentions (Servlet, JSP or HTML) can be used in the include(...) method.
When I use a HTML file, I get
IllegalStateException......getOutputStream() has already been called for this response
Any help is appreciated.
Thanks.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
This is the one I cannot recreate.
It runs, but no output from the included html file is shown.


Guy
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Maybe there's something in the log files, could you please check. Also if your borwser is using a user-friendly error page then you might want to turn it off. If you see a blank page, you could also try "View Source" and see what response you got back.
I was running with Tomcat 4.0.1 on WinNT.
Thanks.
- satya
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
satya - There is nothing in either 'catalina.out' or the daily 'localhost' log file regarding the request/response. I 'tail -f' these in separate terminals as the system runs, very easy to see.
I even put in a System.out.println in the scriptlet as a sanity check, that shows in 'catalina.out'.
I have no new ideas on this problem at present.
Regards, Guy
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
What does the "view source" show?
Thanks for checking.
- satya
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
Satya would u check your servlet code that is translated from jsp ? ( I can't do any test on this machine that I am responding from , has nothing loaded, which is related to Java )
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Generated Servlet code:
Currently, using Tomcat 4.0.1 on Windows 98.
Thanks.
- satya

Srini Admala
Ranch Hand

Joined: Dec 04, 2001
Posts: 50
I tried satya's code and got the same IllegalStateException.
I thought about it for sometime as why the buffer is getting flushed.
Then I tried the following and it worked fine.


Can you please try it ?
I remember it works on weblogic. I shall try it tomorrow on Weblogic and let you know.
-Srini
Srini Admala
Ranch Hand

Joined: Dec 04, 2001
Posts: 50
I'm using Tomcat 4.0.1 on windows 2000
Here's the code I used.

-srini
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072

and line 71 equals to this line:

ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
it is crashing when it is trying to release the page context !
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
I thought about it for sometime as why the buffer is getting flushed.
Then I tried the following and it worked fine.
buffer="none"

So what are you trying to say?
If you use buffer="none", the container should flush. If not, the default buffer="8kb" atleast, and so the page maynot be flushed.

Can someone try it one other web apps and let me know, please.
Thanks.
- satya
ps:
I am willing to take anyone of these explanations:
1. The API/Spec again screwed up.
2. Its a bug in Tomcat 4.0.1
and no don't try to blame it on Microsoft or Jupiter-Mercury-Pluto alignment!
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Couple more comments..............
1. The result is the same even when you forward to a HTML page.
2. It (both) works okay if you rename the "junk.html" to "junk.jsp".

- satya
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
satya - This phenomenon is being chatted about in the 'tomcat-users' group.
I have not yet had time to absorb all the details of those conversations yet. Use "flush" as keyword for search.
Check it out at:
tc users archives
Regards, Guy
HL
Greenhorn

Joined: Feb 13, 2002
Posts: 4
I tried the running code on tomcat 4.0.1 and windows 2000 - but am not able to reproduce the exception.
Only thing was it only showed the included file so tried to flush the data and it showed the lines above and below the included file.
<HTML>
<HEAD>
<TITLE>Test RequestDispatcher........</TITLE>
</HEAD>
<BODY>
<H3>Test RequestDispatcher........</H3>
Hello..................1.2 JSP SPEC<BR>
<%
out.flush();
RequestDispatcher rd = request.getRequestDispatcher("/jsp/index.html");
rd.include(request, response);
%>
<BR>
The end!!!
</BODY>
</HTML>
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
My opinion is there are definite bugs/inconsistencies in TC 4.01 here.
eresin's stack trace in a previous message does not match the source code line numbers in my system (built from sources, not the binary D/L). So I don't get the exceptions everyone else is.
Again, this is currently a common theme on the TC user's discussion group.
Later, Guy
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
Here is the answer I got from apache

Jasper is using a writer to output the page, but the default servlet (used in the include) will use the output stream if it can.
So it doesn't work (it's forbidden by the servlet API). Flushing before the include should fix it.

[ March 21, 2002: Message edited by: ersin eser ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Thanks for following up ersin.
- satya
 
 
subject: RequestDispatcher include throws IllegalStateException?
 
Threads others viewed
State true or false...
servlet init parameters for jsp
frecuent users with cookies
Output of RequestDispatcher include with JSP?
Problem displaying implicit request attributes on the forwarded page.
IntelliJ Java IDE