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

jsp:include throws Exception

Nitin Gogia

Joined: Jan 17, 2003
Posts: 22
I m trying to include (<jsp:include> output of servlet in my JSP page. I get following exception:-
at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(
at endoworks.framework.FileA.loadData(
where line 1138 in FileA is
ServletOutputStream sos = response.getOutputStream
Please let me know where m i going wrong.
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Hi Nitin
An IllegalStateException is generally thrown when an attempt is made to use the response object after the response has already been committed to the client.
That is, it is likely that the response in your servlet was committed at some point prior to: "ServletOutputStream sos = response.getOutputStream".
You can always check whether the response has been committed or not by using ServletResponse.isCommitted(), where a return value of 'false' indicates that the response has not yet been committed.
Hope this helps. Post more code if not
Nitin Gogia

Joined: Jan 17, 2003
Posts: 22
I am doing response.isCommitted check before calling <jsp:include...>
Here is what i am trying to achieve :-
I have a jsp page the contents of which are static (character data). Now at the end of the page i need to call servlet to include dynamic contents (binary data). And in the servlet i set the buffer size and after that trying to get Output Stream where actually the code fails and i get an exception as described above. (NOTE :- The servlet has been tested and it works fine. No problem with servlet).
I tried to decompile ServletResponseWrapperInclude.class from jasper_runtime.jar file to trace the error. The method in that class file is throwing IllegalStateException when i call getServletOutputStream in my servlet. I am confused where actually the error is.
If i call jsp:forward i get the dynamic contents to be displayed but static data in buffer erases out which is the right behaviour.
jsp:include not working.
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Here's another thought...
Your JSP page, in it's servlet capacity, has called getWriter() on the response object to write out the static contents of the JSP page.
Ok so far. But now your included servlet attempts to get a ServletOutputStream on the same response object. This will cause an IllegalStateException. You may have one or the other, PrintWriter or ServletOutputStream. Not both.
Hope this helps.
Nitin Gogia

Joined: Jan 17, 2003
Posts: 22
I know it is creating the problem. But how do i fix it. I have a page with static contents and at the end of the page i have to display an image (binary data). Image is served via servlet.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
You can't include binary image data in the page, you have to write an <img tag that points to the servlet that will generate the image data.
Remember, getting an image into a page takes a separate browser request and that data can't be output by a JSP because it is binary not character.
I agree. Here's the link:
subject: jsp:include throws Exception
It's not a secret anymore!