[英]Spring MVC : java.lang.IllegalStateException: getOutputStream() has already been called for this response
java.lang.IllegalStateException: getOutputStream() has already been called for this response java.lang.IllegalStateException: 已经为此响应调用了 getOutputStream()
I am getting above error at return statement.我在返回语句中遇到以上错误。 In below two statements in method either one statement is working fine but not both.在方法的下面两个语句中,其中一个语句工作正常,但不能同时工作。
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
ExcelUtils.downloadExcel(response.getOutputStream(), getExportData(command.getFile(), errors));
return this.showForm(request, response, errors);
}
Here I am trying to download excel file and return to page to display message.我在这里尝试下载 excel 文件并返回页面以显示消息。 Can we can't call response.getOutputStream() and this.showForm(request, response, errors) or return new ModelAndView("redirect:/importPage.do") or return new ModelAndView("forward:/importPage.do") in single flow?我们不能调用 response.getOutputStream() 和 this.showForm(request, response, errors) 或 return new ModelAndView("redirect:/importPage.do") 或 return new ModelAndView("forward:/importPage.do")在单流?
If you have this problem only the second time you export, try adding:如果您只是在第二次导出时遇到此问题,请尝试添加:
response.getOutputStream().flush();
response.getOutputStream().close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.