Why do I get an IllegalStateException when using <jsp:include> on a css or js file?

Jeff Turner

When I try something like
<jsp:include page="default.css" flush="true"/>
or
<jsp:include page="widget.js" flush="true"/>
I get an IllegalStateException.


This applies to Tomcat 4.0. I haven't encountered it on earlier versions.
Answer supplied by developer Remy Maucherat on the tomcat-user mailing list:
The behavior is valid, but is easy to fix.

Here, the JSP page uses a writer. Since the static page server is also a
servlet, it can't use an output stream to output the data (you'll get that
ISE if you call getOutputStream()). It will attempt to use the writer in
that particular case, but only if the file being included is a text file
(it's the case here, but there's no MIME type for .js).

The test used is that the MIME type of the included file has to be starting
with "text".

Adding the following mapping in your web.xml should make it work:
  <mime-mapping>
    <extension>js</extension>
    <mime-type>text/plain</mime-type>
  </mime-mapping>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact