Tomcat异常在提交响应后无法调用sendError()?

23 java tomcat struts2 netbeans-7

我在应用程序中执行某些操作时得到了

java.lang.IllegalStateException无法调用sendError()

当我再次重新加载页面时,它会正常工作一段时间,但经过一段时间再次显示相同的异常.我怎样才能克服这个例外?

以下是例外情况:

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.
Run Code Online (Sandbox Code Playgroud)

在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>
Run Code Online (Sandbox Code Playgroud)

Bar*_*ett 26

此错误是其他一些问题的症状,而不是您正在寻找的根本原因.

此错误解释了无法将用户重定向到错误页面的原因.(原因:服务器已经将部分响应缓冲区刷回客户端 - 切换/重定向到错误页面为时已晚.)

正如错误消息所指出的那样,检查Apache Tomcat 7日志中的其他位置(或以其他方式调试应用程序)以查找引发异常的内容.

  • 在此附加@LukaszFrankowski 的评论。要调试并查找实际的根本原因,请按照以下步骤操作: 1) 检查完整堆栈跟踪的顶部并找到“ResponseFacade.sendError”。如果您看到此内容,请继续执行第二步。2) 从顶部跳到第一行不以 `.sendError(...)` 结尾的行,例如,跳过 `HttpServletResponseWrapper.sendError`、`OnComfilledResponseWrapper.sendError` 等内容。3)查找您停下来的班级。这通常是实际根本原因所在的位置,因为它尝试在那里调用“HttpServletResponse.sendError”方法。 (2认同)

Med*_*edo 6

我通过向@jsonIgnore所有getter 添加另一个对象的List来解决了这个错误


小智 6

对于其他处于我这种情况的人来说——发生的事情是我有两个具有多对多关系的 @Entity 对象,导致生成无限的 json,导致 spring security 抛出此错误。尝试在休眠关系之上添加@JsonIgnore。


Dip*_*wla 5

您可以尝试这个注释,它会有所帮助,因为它解决了我的问题。

如果它不能帮助您,那么它肯定会有所帮助,然后尝试根据您的要求进行修改。

@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
   @JsonIdentityReference(alwaysAsId=true)
Run Code Online (Sandbox Code Playgroud)

  • 它对我有用!谢谢,如果我们想忽略除 id 之外的所有其他属性,则只需添加 @JsonIdentityReference(alwaysAsId=true),否则删除 @JsonIdentityReference(alwaysAsId=true) (2认同)

Asa*_*sad 5

我正在创建一个@ManyToOne和@OneToMany关系。我在@ManyToOne上方添加了@JsonIgnore,它解决了该错误。

  • 完美的解决方案,对我有用,因为我们在 Hibernate 模型实体中添加了 @OneToMany。 (2认同)
  • 从这里导入 `import com.fasterxml.jackson.annotation.JsonIgnore;` (2认同)

小智 5

注意:您可以导入 2 个@JsonIgnore依赖项。确保它来自杰克逊图书馆;这对我来说很重要:

import com.fasterxml.jackson.annotation.JsonIgnore;
Run Code Online (Sandbox Code Playgroud)