Scope 'session' is not active for the current thread《转》
1、问题一
用struts2做查询,当不同客户端查询时,a端会看到b端的查询结果,导致原因scope="singleton"
解决方法:
要将bean中的scope设置成“session【session作用域的bean则对每次http Session有效】
<bean id="assetAction" class="com.servicezone.itsd.asset.webapp.action.AssetAction"scope="session">
<property name="assetManager" ref="assetManager"/>
<property name="itProductManager" ref="itProductManager"/>
<property name="vendorManager" ref="vendorManager"/>
<property name="assetManager" ref="assetManager"/>
<property name="itProductManager" ref="itProductManager"/>
<property name="vendorManager" ref="vendorManager"/>
</bean>”
于是出现如下异常
Struts Problem Report
Struts has detected an unhandled exception:
Messages: |
|
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>
转自--http://blog.csdn.net/woshirongshaolin/article/details/8251062