Tomcat exception Cannot call sendError() after the response has been committed?

85,130

Solution 1

I was creating a @ManyToOne and @OneToMany relationship. I added @JsonIgnore above the @ManyToOne and it solved the error.

Solution 2

This error is a symptom of some other problem, not the root cause you're looking for.

This error explains why the user can't be redirected to the error page. (Reason: the server has already flushed part of the response buffer back to the client - it's too late to switch/redirect to the error page.)

As the error message points out, check elsewhere in your Apache Tomcat 7 logs (or debug your app another way) to find what is throwing an exception.

Solution 3

I solved this error by adding @jsonIgnore to all getters for a List of another object

Solution 4

Note: there are 2 @JsonIgnore dependencies you can import. Make sure it's from Jackson library; that made the difference for me:

import com.fasterxml.jackson.annotation.JsonIgnore;

Solution 5

For others in my situation--What was happening was that I had two @Entity objects with a many to many relationship causing infinite json to be generated, causing spring security to throw this error. Try adding @JsonIgnore above your hibernate relationships.

Share:
85,130
Admin
Author by

Admin

Updated on November 18, 2021

Comments

  • Admin
    Admin over 2 years

    While doing some operations in my application I got

    java.lang.IllegalStateException Cannot call sendError()

    When I reload the page again it work some time properly, but after some time again it shows the same exception. How can I overcome this exception?

    Below is the exception:

    HTTP Status 500 - Cannot call sendError() after the response has been committed
    type Exception report
    message Cannot call sendError() after the response has been committed
    description The server encountered an internal error that prevented it from fulfilling this request.
    exception 
    java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
    org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)
    org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:725)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.40 logs.
    

    Struts.xml

    <struts>
        <package name="default" extends="hibernate-default">
            <action name="addUser" method="add" class="com.demo.action.UserAction">
                <result name="input">/register.jsp</result>
                <result name="success" type="redirect">list</result>
            </action>
            <action name="list" method="list" class="com.demo.action.UserAction">
                <interceptor-ref name="basicStackHibernate" />
                <result name="success">/list.jsp</result>
            </action>
        </package>
    </struts>