Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher include throws IllegalStateException?

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the one I cannot recreate.
It runs, but no output from the included html file is shown.


Guy
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the "view source" show?
Thanks for checking.
- satya
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generated Servlet code:
Currently, using Tomcat 4.0.1 on Windows 98.
Thanks.
- satya

 
Srini Admala
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Tomcat 4.0.1 on windows 2000
Here's the code I used.

-srini
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and line 71 equals to this line:

 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is crashing when it is trying to release the page context !
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for following up ersin.
- satya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic