在 Java Web 应用程序中,我在 Jboss 4.2.3 上使用 Stripes 框架。在我的 JSP 中使用时
<c:import url="http://localhost:8080/contextPath/txts/someID" charEncoding="UTF-8"/>
效果很好,内容包含在输出 HTML 中。但是,这不起作用
<c:import url="/txts/someID" charEncoding="UTF-8"/>
它抛出这个错误(整个堆栈太大无法粘贴在这里,所以我包括前几行):
java.lang.IllegalStateException: Unexpected internal error during <import>: Target servlet called getOutputStream(), then getWriter()
at org.apache.taglibs.standard.tag.common.core.ImportSupport$ImportResponseWrapper.getOutputStream(ImportSupport.java:492)
at net.sourceforge.stripes.action.StreamingResolution.stream(StreamingResolution.java:443)
at net.sourceforge.stripes.action.StreamingResolution.execute(StreamingResolution.java:240)
at net.sourceforge.stripes.controller.DispatcherHelper$7.intercept(DispatcherHelper.java:508)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
at org.stripesstuff.plugin.security.SecurityInterceptor.interceptResolutionExecution(SecurityInterceptor.java:225)
at org.stripesstuff.plugin.security.SecurityInterceptor.intercept(SecurityInterceptor.java:129)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at net.sourceforge.stripes.controller.HttpCacheInterceptor.intercept(HttpCacheInterceptor.java:99)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
at net.sourceforge.stripes.controller.DispatcherHelper.executeResolution(DispatcherHelper.java:502)
at net.sourceforge.stripes.controller.DispatcherServlet.executeResolution(DispatcherServlet.java:286)
at net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
如有任何建议,我们将不胜感激。
问候
最佳答案
问题是,如果 StreamingResolution 使用 Reader 打开,那么它(自然地)打开 Writer 以流式传输输出。 c:import 标签不关心,只是在响应上调用 getOutputStream。
因此,为了缓解这种情况,您不应为 StreamingResolution 使用 Reader,而需要使用 InputStream 创建 StreamingResolution。
另一种选择是覆盖 StreamingResolution.stream() 方法。
Stripes 基本上是为您“做正确的事”,但 c:import 正在为您的游行而下雨。
谢天谢地,您可以控制 Stripes 操作。与其说是 c:imports 操作。
关于java - JSTL 导入标签抛出带有相对 URL 的 java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5642067/