Struts2下载文件点取消出现的异常java.lang.IllegalStateException 解决方案
2013-03-19 19:36
597 查看
在使用Struts2下载文件时,如果点击保存或打开,没问题,点击取消时则会抛出如下异常:
严重: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:108)
at com.opensymphony.module.sitemesh.filter.PageResponseWrapper.sendError(PageResponseWrapper.java:176)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:108)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
原因:
stream对应的类是org.apache.struts2.dispatcher.StreamResult,该类的处理过程如下:
1、配置其中result标签下的各个参数
2、从服务器中获取输入流,并同时与客户端建立输出流(服务器与客户端链接通过Socket进行连接)
3、当点击“保存”或“打开”时,开始传输数据。如果点击“取消”,关闭所有的流
但是实际发现Socket并没有断开,并且流也没有关闭,所以在JSP容器通过Response获取输出流之前,前面的流并没有关闭,所以会造成该异常的报出
解决方法:
1、下载struts2-sunspoter-stream-1.0.jar,复制到WEB-INF/lib下
2、在原有的struts.xml的基础上进行相应的配置,如下:
<package name="e3itm" extends="struts-default">
<result-types>
<!-- 用于处理下载文件点击取消时报出异常问题 -->
<result-type name="streamx" class="com.sunspoter.lib.web.struts2.dispatcher.StreamResultX"></result-type>
</result-types>
<action name="download" class="com.DownloadAction">
<result name="success" type="streamx">
<param name="inputName">download</param>
<param name="bufferSize">4096</param>
<param name="contentDisposition">filename=""</param>
<param name="contentCharSet">UTF-8</param>
</result>
</action>
</package>
红色部分为添加的部分,并在原有的result中type改为“streamx”
如果是使用注解方式同样如下:
@Result(type="streamx", params={"inputName","inputStream","bufferSize","4096", "contentDisposition", "attachment;filename=\"${downloadFileName}\""})
修改之后执行取消,效果如下:
[WARN] StreamResultX Warn : socket write error
严重: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:108)
at com.opensymphony.module.sitemesh.filter.PageResponseWrapper.sendError(PageResponseWrapper.java:176)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:108)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
原因:
stream对应的类是org.apache.struts2.dispatcher.StreamResult,该类的处理过程如下:
1、配置其中result标签下的各个参数
2、从服务器中获取输入流,并同时与客户端建立输出流(服务器与客户端链接通过Socket进行连接)
3、当点击“保存”或“打开”时,开始传输数据。如果点击“取消”,关闭所有的流
但是实际发现Socket并没有断开,并且流也没有关闭,所以在JSP容器通过Response获取输出流之前,前面的流并没有关闭,所以会造成该异常的报出
解决方法:
1、下载struts2-sunspoter-stream-1.0.jar,复制到WEB-INF/lib下
2、在原有的struts.xml的基础上进行相应的配置,如下:
<package name="e3itm" extends="struts-default">
<result-types>
<!-- 用于处理下载文件点击取消时报出异常问题 -->
<result-type name="streamx" class="com.sunspoter.lib.web.struts2.dispatcher.StreamResultX"></result-type>
</result-types>
<action name="download" class="com.DownloadAction">
<result name="success" type="streamx">
<param name="inputName">download</param>
<param name="bufferSize">4096</param>
<param name="contentDisposition">filename=""</param>
<param name="contentCharSet">UTF-8</param>
</result>
</action>
</package>
红色部分为添加的部分,并在原有的result中type改为“streamx”
如果是使用注解方式同样如下:
@Result(type="streamx", params={"inputName","inputStream","bufferSize","4096", "contentDisposition", "attachment;filename=\"${downloadFileName}\""})
修改之后执行取消,效果如下:
[WARN] StreamResultX Warn : socket write error
相关文章推荐
- javaIE下载文件中取消下载出现ClientAbortException: java.io.IOException异常
- Struts2下载文件点取消、重复下载出现的异常解决
- struts2下载文件时出现:java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to 错误
- Servlet.service() for servlet jsp threw exception java.lang.Il在jsp中使用jspsmartupload组件下载文件时将抛出异常的解决方案
- struts2 下载文件报 “java.lang.IllegalStateException”异常
- struts2下载文件时出现:java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to 错误
- 防止使用Struts2下载时取消出现异常,并实现支持下载完成后删除临时文件
- Struts2下载文件点取消出现的异常解决
- Struts2下载文件点取消出现的异常解决
- Struts2下载文件点取消出现的异常解决
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- 关于Tomcat启动出现java.lang.ClassNotFoundException异常的解决方案
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- hdfs下载文件时出现Exception in thread "main" java.lang.NullPointerException
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
- Struts2上传文件异常: java.lang.RuntimeException: Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta
- 遇到问题----struts2文件下载出现Can not find a java.io.InputStream with the name的错误