java.lang.IllegalStateException异常解决

在用java做导出功能的时候,前台可以正常导出数据,但是后台总是报错java.lang.IllegalStateException,我的后台代码是这样写的

LogBean[] logBeans = LogBean.getAllLog(sqlSession, record, "ID DESC", typeList);
exportExcel(logBeans, response);//这个是执行导出excel的方法
forward = new ActionForward("/log.html");
forward.setRedirect(true);

后来百度了一下,说需要在response.sendRedirect("")方法后加return语句即可:
原因是在程序中两次调用response.sendRedirect("")方法。我就在最后加上了return null。果然就没有再报错。
j2EE1.5帮助文档

sendRedirect
void sendRedirect(String location)
throws IOExceptionSends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.


Parameters:
location - the redirect location URL
Throws:
IOException - If an input or output exception occurs
IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值