JSTL 导入标记抛出带有相对 URL 的 java.lang.IllegalStateException
在 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)
任何建议将不胜感激。
问候
In a Java web application I am using the Stripes framework on Jboss 4.2.3. In my JSP when I use
<c:import url="http://localhost:8080/contextPath/txts/someID" charEncoding="UTF-8"/>
It works great and the the contents are included in the output HTML. However, this does not work
<c:import url="/txts/someID" charEncoding="UTF-8"/>
and it throws this error (the whole stack is too big to paste here, so I include the first few lines):
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)
Any advice would be appreciated.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是,如果使用 Reader 打开 StreamingResolution,那么它(自然)会打开 Writer 以流式传输输出。 c:import 标记并不关心,只是在响应上调用 getOutputStream。
因此,为了缓解这种情况,您不应该为 StreamingResolution 使用 Reader,而是需要使用 InputStream 创建 StreamingResolution。
另一个选项是重写 StreamingResolution.stream() 方法。
Stripes 基本上是为你“做正确的事”,但 c:import 却给你带来了麻烦。
值得庆幸的是,您可以控制 Stripes 的操作。与 c:imports 操作无关。
The problem is that if the StreamingResolution is opened with a Reader, then it (naturally) opens a Writer to stream the output out. The c:import tag doesn't care, and simply calls getOutputStream on the response.
So, to mitigate this you should not use a Reader for your StreamingResolution, rather you need to create the StreamingResolution with a InputStream.
The other option is to override the StreamingResolution.stream() method.
Stripes is basically "doing the right thing" for you, but the c:import is raining on your parade.
Thankfully, you have control over Stripes actions. Not so much over c:imports actions.
问题不在于 JSTL,而在于目标 servlet。异常消息很明确 - 您不应为相同的响应调用
getOutputStream()
和getWriter()
。The problem is not in JSTL, but in the target servlet. The exception message is clear - your should not call
getOutputStream()
andgetWriter()
for the same response.