欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Cannot call reset() after response has been committed

程序员文章站 2022-06-26 16:59:01
下载文件报错...

前言

下载文件报错

 java.lang.IllegalStateException: Cannot call reset() after response has been committed
	at org.apache.catalina.connector.ResponseFacade.reset(ResponseFacade.java:347)
	at ins.platfrom.services.FileService.downloadTemplate2(FileService.java:1215)
	at ins.platfrom.controller.FileController.downloadTemplate(FileController.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)

原因

响应需要提前清空 然后再获取输出流 顺序不能颠倒 测试中发现

     // 清空response
            response.reset();
            fis =new FileInputStream(fileName);
            out = response.getOutputStream();

本文地址:https://blog.csdn.net/HezhezhiyuLe/article/details/114268554

相关标签: POI JavaSE io