struts2文件图片流输出报IllegalStateException: Cannot call sendError() after the response has been committed
来源:互联网 发布:批处理自动卸载软件 编辑:程序博客网 时间:2024/05/21 19:48
struts2图片后端以流的形式传给前端并显示时,控制台报java.lang.IllegalStateException: Cannot call sendError() after the response has been committed异常.
文件可以正常下载,只是后台报异常.
未修改前代码如下:
try{ VO vo = new VO(); String filepath = Param.getValue("LOCALACTIVITY", "FILEPATH")+id+postfix; System.out.println("filepath"+filepath); File file = new File(filepath); DataOutputStream temps = new DataOutputStream(response.getOutputStream());; DataInputStream in = null; response.setContentType("image/*"); if (file.exists() ) { in = new DataInputStream(new FileInputStream(file)); int len=0; byte[] b = new byte[2048]; while ((len=in.read(b)) != -1) { temps.write(b,0,len); temps.flush(); } in.close(); temps.close(); } else{ file = new File(Param.getValue("LOCALACTIVITY", "FILEPATH")+"\\default\\default.png"); in = new DataInputStream(new FileInputStream(file)); int len=0; byte[] b = new byte[2048]; while ((len=in.read(b)) != -1) { temps.write(b,0,len); temps.flush(); } in.close(); temps.close(); } } catch (Exception e) { log.debug("===========查询图片时报错"+e); } log.debug("===========查询图片结束"); return SUCCESS;
研究发现可能是struts2本身的bug,将return SUCCESS 改为return null,即可解决问题.
需要注意的地方:
1.在各分支内部关闭输出流,不要统一关闭.
阅读全文
0 0
- struts2文件图片流输出报IllegalStateException: Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed错误
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- Struts2中使用servletresponse直接输出内容到客户端出现:Cannot call sendError() after the response has been committed
- struts2文件下载,解决jCannot call sendError() after the response has been committed的问题
- 【SSH异常系列】Cannot call sendError() after the response has been committed
- Cannot call sendError() after the response has been committed 错误记录
- 【SSH问题】java.lang.IllegalStateException: Cannot call sendError() after the response has been committe
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- GlobalPlatform TEE Protection Profile (PP)Version 1.2.1 A.3 攻击路径举例(一)
- 使用小波变换重构某个节点的信号
- 获取外网本机的IP地址的方法
- Java
- 4.静态链接
- struts2文件图片流输出报IllegalStateException: Cannot call sendError() after the response has been committed
- 站在JAVA数据结构的视角看待简单表结构
- Redis使用三、redis的配置与使用
- ISIS报文结构—P2P IIH
- java是如何实现位移运算的
- Android 实时监听耳机拔除
- 基于 STM32 的硬件 I2C 读取 MPU6050 数据
- Intent 使用方法详解
- 再按一次推出程序