I think this is closely related to the bug reported by Todd Fast on the 15th
of June. (See http://www.metronet.com/~wjm/tomcat/FromFeb11/msg02927.html).
We're trying to port an existing JSP-based web application to Tomcat 3.1 /
JSP 2.2. The general design is a "gatekeeper" servlet, which forwards
requests to JSPs. This works fine, except in the case of a few JSPs, which
themselves use <jsp:include> directives to dispatch dynamically. They throw
the exception
java.lang.IllegalStateException: Response has already been committed
at org/apache/tomcat/core/HttpServletResponseFacade.sendError
(HttpServletResponseFacade.java:157)
at org/apache/jasper/runtime/JspServlet$JspServletWrapper.service
(JspServlet.java:184)
at org/apache/jasper/runtime/JspServlet.serviceJspFile
(JspServlet.java:248)
at org/apache/jasper/runtime/JspServlet.service
(JspServlet.java:338)
at javax/servlet/http/HttpServlet.service (HttpServlet.java:841)
at org/apache/tomcat/core/ServletWrapper.handleRequest
(ServletWrapper.java:507)
at org/apache/tomcat/core/RequestDispatcherImpl.include
(RequestDispatcherImpl.java:266)
at org/apache/jasper/runtime/PageContextImpl.include
(PageContextImpl.java:346)
at
_0002fSSS_0002fTest_0002fOuter_0002ejsp_0002fSSS_0002fTest_0002fOuter_jsp_1.
_jspService
(_0002fSSS_0002fTest_0002fOuter_0002ejsp_0002fSSS_0002fTest_0002fOuter_jsp_1
.java:66)
...
I was able to replicate this problem with a minimal set of files -- see
below. Is this a real bug, or an error on our part? If it's a bug, is
there a fix planned? And is there a workaround? Thanks,
Vance
The servlet is in a package "test", and the JSPs are in a virtual directory
"/test".
-- begin test/Test.java --
package test;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Simplest possible test of problem configuration:
* servlet forwards request to JSP, JSP includes another.
*/
public class Test
extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
RequestDispatcher rd =
this.getServletContext().getRequestDispatcher("/test/Outer.jsp");
rd.forward(request, response);
}
}
-- begin /test/Outer.jsp --
<html>
<head>
<title>Include test</title>
</head>
<body>
This is a test of forwarding and inclusion. For some reason, it's not
working right for us with Tomcat.
<p>
<jsp:include page="/test/Inner.jsp" flush="true" />
</body>
</html>
-- begin /test/Inner.jsp --
This is an inner file included via <jsp:include>.
|