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"/> 
    </bean>”
于是出现如下异常

2、问题二

Struts Problem Report

Struts has detected an unhandled exception:

Messages:
  1. 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.
  2. 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.
  3. 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>


转自--http://blog.csdn.net/woshirongshaolin/article/details/8251062

转载于:https://www.cnblogs.com/auto714/archive/2013/02/27/2935732.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值