使用struts2下载出错getOutputStream() has already been ca

本文解决了一个Struts框架中因方法间调用导致的java.lang.IllegalStateException:getOutputStream()hasalreadybeencalledforthisresponse错误。通过调整返回值类型并直接处理响应输出,避免了response冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


/**
* 查看图片
* @return
* @throws Exception
*/
public String view() throws Exception {
png= workFlowManager.getPngByte(workFlow.getPdID());
response.reset();
response.setContentType("image/png");
response.getOutputStream().write(png.getFileData());
response.getOutputStream().flush();
response.getOutputStream().close();
return null;
}


调用页面

<a href="#" onclick="openWin('workFlow!view?workFlow.pdID=<s:property value="#wf.pdID" />','updateorg',700,500);">查看定义图</a>



显示页面


<img src="'workFlow!view?workFlow.pdID=<s:property value="#wf.pdID" />" style="position:absolute;left:0px;top:0px;">

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值