gpt4 book ai didi

java - 支柱 2 : Cannot create a session after the response has been committed

转载 作者:行者123 更新时间:2023-11-28 22:03:01 27 4
gpt4 key购买 nike

我需要你的帮助。问题是:

  1. tomcat 在 <session-timeout> 时间后销毁 session 结束了
  2. 用户点击应用内的链接
  3. 我们得到错误:
 java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:725)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Unknown Source)

就像它在内部工作一样:只能为某些操作重现错误。例如这个 url 重现问题

localhost:8080/myapp/editPromotion?promoId=TestBes

这个不是

localhost:8080/myapp/searchCustomerHome

拦截器对这些 url 的工作方式相同

public String intercept(ActionInvocation invocation) throws Exception {
if (!isLoginAction(invocation)) {
Map<String, Object> sessionMap = ActionContext.getContext().getSession();

if (sessionMap.get(LoginAction.USER_NAME) == null) {
return "notAuthenticated";
}
}

return invocation.invoke();
}

并返回“notAuthenticated”。

我在struts.xml中也有这段代码:

    <global-results>
<result name="notAuthenticated" type="redirect">login</result>
</global-results>

唯一不同的错误请求转到了

org.apache.struts2.interceptor.MessageStoreInterceptor.java

开始运行

public String intercept(ActionInvocation invocation) throws Exception {
LOG.debug("entering MessageStoreInterceptor ...");

before(invocation);
String result = invocation.invoke();
after(invocation, result);

LOG.debug("exit executing MessageStoreInterceptor");
return result;
}

我不知道为什么它们的工作方式如此不同。

最佳答案

我遇到了同样的问题 - 一切都很好,直到 session 超时,根据请求的操作我会看到这个异常。

我通过在操作中添加“createSession”拦截器作为第一个拦截器解决了这个问题,它解决了这个问题。

关于java - 支柱 2 : Cannot create a session after the response has been committed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20067441/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com