You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Scott M Stark <Sc...@jboss.org> on 2001/09/30 04:58:42 UTC

IllegalStateException on jsp:include in simple jsp page

This simple tst.jsp page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title>Tst.jsp</title>
 <link rel="stylesheet" type="text/css" href="tst.css" >
 <jsp:include page="tst.js" flush="true" />
</head>

<body>
<h1>Tst.jsp is OK!</h1>
</body>
</html>

is producing an IllegalStateException on the inclusion of the tst.js file
when using
the current jakarta-tomcat-4.0 binary release. The same tst.jsp file works
fine
when using the jakarta-tomcat-3.2.3 release. I don't see that I have much
control
preventing the call to obtain the request output stream so how do I prevent
this
error, and is this valid behavior? The full exception is given below as well
as the tst.css and tst.js files.

java.lang.IllegalStateException
 at
org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(Unkn
own Source)
 at org.apache.catalina.servlets.DefaultServlet.serveResource(Unknown
Source)
 at org.apache.catalina.servlets.DefaultServlet.doGet(Unknown Source)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source)
 at org.apache.catalina.core.ApplicationDispatcher.doInclude(Unknown Source)
 at org.apache.catalina.core.ApplicationDispatcher.include(Unknown Source)
 at org.apache.jasper.runtime.JspRuntimeLibrary.include(Unknown Source)
 at org.apache.jsp.tst$jsp._jspService(tst$jsp.java:60)
 at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown
Source)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
 at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown
Source)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
 at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
 at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
 at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Unknown
Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.valves.CertificatesValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
 at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
 at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
 at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
 at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
 at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
 at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
 at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
 at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
 at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
 at java.lang.Thread.run(Thread.java:484)


tst.css:
.slogan     {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 15px;
 color: #338833;
 font-weight: bold;
 background-color : transparent;
}

tst.js:
<script type="text/javascript" language="JavaScript">
</script>



[PATCH] Prevent IllegalStateExceptions on

Posted by Jeff Turner <je...@socialchange.net.au>.
Hi,

As was reported on tomcat-user, the following JSP will throw an
IllegalStateException:

<jsp:include page="/ssi/generic.js" flush="true" /> 

Remy explained why in the following post, and suggested as a fix that
the following be added to the webapp's web.xml:

>   <mime-mapping>
>     <extension>js</extension>
>     <mime-type>text/plain</mime-type>
>   </mime-mapping>


So how about adding this to Catalina's default web.xml, and save many
people from rediscovering this?

The attached patch does this for *.js and *.css, using the official MIME
types rather than text/plain.

thanks,

--Jeff


On Sun, Sep 30, 2001 at 10:42:26AM -0700, Remy Maucherat wrote:
> > This simple tst.jsp page:
> >
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> > <html>
> > <head>
> >  <title>Tst.jsp</title>
> >  <link rel="stylesheet" type="text/css" href="tst.css" >
> >  <jsp:include page="tst.js" flush="true" />
> > </head>
> >
> > <body>
> > <h1>Tst.jsp is OK!</h1>
> > </body>
> > </html>
> >
> > is producing an IllegalStateException on the inclusion of the tst.js file
> > when using
> > the current jakarta-tomcat-4.0 binary release. The same tst.jsp file works
> > fine
> > when using the jakarta-tomcat-3.2.3 release. I don't see that I have much
> > control
> > preventing the call to obtain the request output stream so how do I
> prevent
> > this
> > error, and is this valid behavior? The full exception is given below as
> well
> > as the tst.css and tst.js files.
> 
> 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>
> 
> Remy

Re: IllegalStateException on jsp:include in simple jsp page

Posted by Remy Maucherat <rm...@home.com>.
> This simple tst.jsp page:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
>  <title>Tst.jsp</title>
>  <link rel="stylesheet" type="text/css" href="tst.css" >
>  <jsp:include page="tst.js" flush="true" />
> </head>
>
> <body>
> <h1>Tst.jsp is OK!</h1>
> </body>
> </html>
>
> is producing an IllegalStateException on the inclusion of the tst.js file
> when using
> the current jakarta-tomcat-4.0 binary release. The same tst.jsp file works
> fine
> when using the jakarta-tomcat-3.2.3 release. I don't see that I have much
> control
> preventing the call to obtain the request output stream so how do I
prevent
> this
> error, and is this valid behavior? The full exception is given below as
well
> as the tst.css and tst.js files.

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>

Remy