java.io.IOException: Stream closed org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:202) org.apache.jasper.runtime.JspWriterImpl.clearBuffer(JspWriterImpl.java:157) org.apache.jsp.WEB_002dINF.pages.tilestest.main_jsp._jspService(main_jsp.java:76) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274) org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012) org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345) org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:582) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:260) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507) javax.servlet.http.HttpServlet.service(HttpServlet.java:689) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
以下是相關檔案:
---------------------main.jsp----------------------------
<table width="100%">
<tr>
<td width="50%" valign="top">
<jsp:include page="/sub1.do"/>
</td>
</tr>
<tr>
<td><jsp:include page="/sub2.do"/></td>
</tr>
</table>
--------------struts-config.xml------------------------
<action-mappings>
<action path="/tilestest" forward="/WEB-INF/pages/tilestest/main.jsp"/>
<action path="/sub1" forward="testTilesSub1"/>
<action path="/sub2" forward="/WEB-INF/pages/tilestest/sub2.jsp"/>
</action-mappings>
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/struts/tiles-defs.xml"/>
<set-property property="moduleAware" value="true"/>
<set-property property="definitions-parser-validate" value="true"/>
</plug-in>
--------------tiles-defs.xml----------------------------------
<tiles-definitions>
<definition name="baseDef" path="/baselayout.jsp">
<put name="title" value="baseDef.title"/>
<put name="header" value="/WEB-INF/pages/titles/header.jsp"/>
<put name="body" value="/WEB-INF/pages/titles/body.jsp"/>
<put name="footer" value="/WEB-INF/pages/titles/footer.jsp"/>
</definition>
<definition name="testTilesSub1" extends="baseDef">
<put name="header" value="/WEB-INF/pages/tilestest/sub1.jsp"/>
</definition>
<definition name="testTilesSub2" extends="baseDef">
<put name="header" value="/WEB-INF/pages/tiletest/sub2.jsp"/>
</definition>
</tiles-definitions>
sub1.jsp和sub2.jsp裡面都只有顯示的文字,如slkdjflksdflakdsflasd
請注意struts-config.xml中sub1和sub2的forward不一樣,用sub1的時候就會出現以上的錯誤。
錯誤解決方案見地址:http://mail-archives.apache.org/mod_mbox/tomcat-dev/200307.mbox/%3C20030709224018.7289.qmail@nagoya.betaversion.org%3E
和http://issues.apache.org/struts/browse/STR-2969
本人的理解:由於我在tiles-defs.xml中用了defination的extends屬性,所以會出現以上錯誤,後來我沒用extends,改用了path屬性,<definition name="testTilesSub1" path="/WEB-INF/pages/tilestest/sub1.jsp"/>這樣就可以了