Cannot call sendredirect() after the response has been committed exception
For the HTTP response, if it has been submitted (redirection, request forwarding, release in the filter), you can’t perform any operation on the response, such as modifying it or submitting it again.
For the submitted response, the method will not end (different from return), it will continue to execute, so if the code that you continue to execute after submitting will still run, the submit response will also cause this error.
For example:
-
- the following code will report an error because it released and submitted the response, and now it operates the response, because the filter release does not return the method, and the method is still executed downward </ OL> instead
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
boolean boo = "Your judgment conditions";
if (boo) {
log.info("enter chain");
chain.doFilter(request, response);
//return;
}
//This is where the error will be reported because the response was submitted in the above release and now the resposne is being operated
httpResponse.sendRedirect(TOLOGINURL);
2. The following code will report an error because it is submitted again after redirection, because the redirection will continue
httpResponse.sendRedirect(TOLOGINURL);
//This will report an error because it was committed (redirected) and then committed again
httpResponse.sendRedirect(TOLOGINURL);
The solution is to return after submitting</ Code>, or the check logic will not enter the submit again.
Read More:
- [Solved] java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- [Redirect anomaly] Cannot call sendRedirect() after the response has been committed
- [Solved] cannot call sendError() after the response has been committed
- [Solved] Cannot call sendError() after the response has been committed
- [Solved] springsecurity custom exceptions: Error: Parse Error: Response overflow
- How to Download File via Response (Example Code)
- [Solved] docker Error response from daemon driver failed programming external connectivity on endpoint lamp
- [Solved] Java.lang.IllegalStateException: getReader() has already been called for this request
- [Solved] Error response from daemon: driver failed programming external connectivity on endpoint mymysql
- Gitee Idea Push Error: Invocation failed Server returned invalid Response. java.lang.RuntimeException
- [Solved] HttpPost Call https Interface error: PKIX path building failed
- [Solved] Spring integrates canal to call feign error: pool-1-thread-1
- Microservice call exceptions: error feign.RetryableException: Read timed out executing POST http://xxx…….
- CORS error has been blocked by CORS policy [How to Solve]
- [Solved] Java.lang.BootstrapMethodError: call site initialization exception
- Feign call Error: duplicate name [How to Solve]
- [Solved] Feign Call Port Error: HttpMessageNotReadableException:JSON parse error:Illegal character ((CTRL-CHAR, code 31)
- [Solved] port (127.0.0.1:64444): java.net.SocketException “Interrupted function call: accept failed“
- Using java to call Jython, the error URI is not hierarchical
- [Solved] Rocketmq remote connection error: sendDefaultimpl call timeout