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即可。