wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:include throws Exception" Watch "jsp:include throws Exception" New topic
Author

jsp:include throws Exception

Nitin Gogia
Greenhorn

Joined: Jan 17, 2003
Posts: 22
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

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
Greenhorn

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
Greenhorn

Joined: Jan 17, 2003
Posts: 22
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
 
 
subject: jsp:include throws Exception
 
Similar Threads
jsp:include Error in Websphere 4.0
Absolute URL in jsp:include
Determine the significance of these
Problme with unzipping
hibernate.cfg.xml not found