Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include throws Exception

 
Nitin Gogia
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I m trying to include (<jsp:include> output of servlet in my JSP page. I get following exception:-
java.lang.IllegalStateException
at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(ServletResponseWrapperInclude.java:109)
at endoworks.framework.FileA.loadData(FileA.java:1138)
where line 1138 in FileA is
ServletOutputStream sos = response.getOutputStream
Please let me know where m i going wrong.
Nitin
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
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
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic