Scope 'session' is not active for the current thread

9553 ワード

1、問題1


struts 2でクエリーを行い、異なるクライアントでクエリーを行うと、a側にb側のクエリー結果が表示され、原因scope=「singleton」になります。


解決方法:


beanのscopeを「session【session役割ドメインのbeanはhttp Sessionごとに有効」に設定する


       
   

そこで次のような異常が発生しました

2、問題2


Struts Problem Report


Struts has detected an unhandled exception:
Messages:
  • No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
  • Error creating bean with name 'qAction': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
  • Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

  • File:
    org/springframework/web/context/request/RequestContextHolder.java
    Line number:
    131

    Stacktraces


    Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction':Scope 'session' is not active for the current thread;consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
        com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
        com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)

    解決策

    (1) Spring's DispatcherServlet Servlet 2.4 Web ( JSF Struts), Web 'web.xml'  javax.servlet.ServletRequestListener  
    <web-app>
      ...
      <listener>

        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

      </listener>
      ...
    </web-app>
    (2) web (Servlet 2.4 ), javax.servlet.Filter 。 web.xml :

    <web-app>
      ..
      <filter> 
        <filter-name>requestContextFilter</filter-name> 
        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
      </filter> 
      <filter-mapping> 
        <filter-name>requestContextFilter</filter-name> 
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      ...
    </web-app>