jxl导出EXCEL的java.lang.IllegalStateException异常
来源:互联网 发布:网络打印机文档挂起 编辑:程序博客网 时间:2024/05/01 06:03
http://blog.csdn.net/patriotlml/archive/2007/05/28/1628556.aspx
我们在做文件上传或者下载,或者过滤等操作时,可能要用到页面的输出流.
例如在JSP使用:
response.reset();
response.setContentType(”application/vnd.ms-excel”);
OutputStream os = response.getOutputStream();
抛出异常:
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
从网上找了下资料,综合一下原因分析:
这是web容器生成的servlet代码中有out.write(””),这个和JSP中调用的response.getOutputStream()产生冲突.
即Servlet规范说明,不能既调用 response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出 IllegalStateException,因为在jsp中,out变量是通过response.getWriter得到的,在程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。
解决方案:
1.在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
2,不要在%][%之间写内容包括空格和换行符
3,在页面写入图片的时候,需要flush()
OutputStream output=response.getOutputStream();
output.flush();
4,在页面确定写入<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312”>
- jxl导出EXCEL的java.lang.IllegalStateException异常
- jxl导出excel异常:java.lang.ArrayIndexOutOfBoundsException: 31
- 解决jxl导出excel异常:java.lang.ArrayIndexOutOfBoundsException
- java异常,java.lang.IllegalStateException,在进行JasperReports导出报表的时候出现的异常
- java.lang.IllegalStateException 异常
- 异常:java.lang.IllegalStateException
- java.lang.IllegalStateException异常的问题
- 我的异常java.lang.IllegalStateException
- Java jxl导出excel
- java jxl导出EXCEL
- java jxl 导出Excel
- java jxl导出excel
- JXL导出Excel抛java.lang.ArrayIndexOutOfBoundsException: 5
- java导出excel jxl的用法
- 用jxl导出excel报错:java.lang.NoClassDefFoundError: jxl/format
- java.lang.IllegalStateException异常解决办法
- java.lang.IllegalStateException异常解决办法
- java.lang.IllegalStateException异常解决
- 主题: 深入了解Java ClassLoader、Bytecode 、ASM、cglib
- 一女孩写的经典“代码”,程序员该如何应对?
- 一个公用的返回信息页面.
- 可定制的数据库备份和恢复程序
- "Linux2.6内核在嵌入式应用上的突破" 勘误
- jxl导出EXCEL的java.lang.IllegalStateException异常
- XHTML+CSS=网站重构
- 关于reflect的应用方法
- hdlc协议的配置
- PB和EAServer共筑多层应用架构
- 斐波那契数列算法汇编实现
- 安装或运行程序时提示 80等端口被占用情况的解决
- 实时和Linux之三:子内核和基准
- 在PB中使用OleControl连接Word,根据需要隐藏部分工具条。