getOutputStream() has already been called for this response的解决方法

1.问题描述:spring mvc中下载文件结束后,跳转到list页面,问题报上面的异常。

2.原因:写文件的时候response调用一次,在跳转的时候,spring调用ActionForward类中也有response,两个response有冲突。

3.解决方法:下载文件结束后不要跳转,直接return null;就行了。或者重写stream,方法如下:

protected void initStreams() {
// Replace System.out and System.err with a custom PrintStream
System.setOut(new SystemLogHandler(System.out));
System.setErr(new SystemLogHandler(System.err));
}

原文地址:https://www.cnblogs.com/nizuimeiabc1/p/6346772.html