java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has been committed

后端 未结 8 1067
南笙
南笙 2020-11-21 11:06

This method throws

java.lang.IllegalStateException: Cannot forward after response has been committed

and I am unable to spot th

8条回答
  •  臣服心动
    2020-11-21 11:53

    Typically you see this error after you have already done a redirect and then try to output some more data to the output stream. In the cases where I have seen this in the past, it is often one of the filters that is trying to redirect the page, and then still forwards through to the servlet. I cannot see anything immediately wrong with the servlet, so you might want to try having a look at any filters that you have in place as well.

    Edit: Some more help in diagnosing the problem…

    The first step to diagnosing this problem is to ascertain exactly where the exception is being thrown. We are assuming that it is being thrown by the line

    getServletConfig().getServletContext()
                      .getRequestDispatcher("/GroupCopiedUpdt.jsp")
                      .forward(request, response);
    

    But you might find that it is being thrown later in the code, where you are trying to output to the output stream after you have tried to do the forward. If it is coming from the above line, then it means that somewhere before this line you have either:

    1. output data to the output stream, or
    2. done another redirect beforehand.

    Good luck!

提交回复
热议问题