Spring中使用request、session、global session作用域bean

 

要使用Spring的request ,session ,global session作用域bean,需要在web.xml中做如下配置:

 

 

1、如果使用Spring Web MVC,即使用SpringDispatcherServlet或DispatcherPorlet来处理请求,此时不需要做额外的

 

     配置,上述SpringDispatcherServlet和DispatcherPorlet已经处理了有关状态。

 

2、使用Servlet2.4及以上的web容器时,需做如下配置:

 

 

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

 

3、使用Servlet2.4以下版本需做如下配置:

 

 

<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-mappiing>
</web-app>

 

  RequestContextListener和RequestContextFilter所做的处理都是一样的:将Http Request对象绑定到为该请求

 

 提供服务的Thread。这使得具有request和session作用域的bean能够在后面的调用链中被访问到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值