今天在用struts2写下载文件的时候遇到getOutputStream()出现异常,和大家分享一下我的解决办法

teny_yan 2013-07-02 10:33:05
使用struts2下载出错getOutputStream() has already been called for this response
报错: java.lang.IllegalStateException: getOutputStream() has already been called for this response的错误. Struts方法之间调用引起的。
因为:每个方法都返回的是一个ActionForward对象,而response是ActionForward对象参数,所以就会使response冲突! 故,将最后的return "SUCCESS"改为 return null .不将其交由sturts管理.


public String exportxl() throws Exception {

if (currentyear != 0) {
HttpServletResponse response = ServletActionContext.getResponse();
DownLoadUtils.downloadLocal(response, "EXP_"+currentyear+"_"+currentmonth);
}
return null;
}
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
rosboy 2013-10-09
  • 打赏
  • 举报
回复
嗯,谢谢撸主,解决了我的问题

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧