Action請求后台出現Response already commited異常解決方法


在編寫導出功能使用action請求,在處理導出異常時期望跳轉異常頁,Controller中的方法返回類型String的url

在處理完邏輯導出文件后后台控制台出現

WARN  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-22) Handling of [org.springframework.http.converter.HttpMessageNotWritableException] resulted in Exception: java.lang.IllegalStateException: UT010019: Response already commited

and

ERROR [io.undertow.request] (default task-22) UT005023: Exception handling request to /snq-admin/data/exportDataDetail.do: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: UT010029: Stream is closed; nested exception is java.io.IOException: UT010029: Stream is closed

Caused by: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: UT010029: Stream is closed; nested exception is java.io.IOException: UT010029: Stream is closed

Caused by: java.io.IOException: UT010029: Stream is closed

在寫入文件時調用requestOutputStream.write()方法已將response發出,再在Controller中return時被認為是再發送一次,因而會報錯,解決這個問題只需返回null即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM