demo 下载:test-stateless.zip
在filter中利用wrapper模式,使用自定义的HttpServletRequest对象和HttpServletResponse对象。这样就可以将自定义的使用memcached存放数据的Session对象放进Request链中,主要的配置如下:
需要是第一个filter
1 2 3 4 5 6 7 8 |
<filter> <filter-name>session</filter-name> <filter-class>net.sourceforge.statelessfilter.filter.StatelessFilter</filter-class> </filter> <filter-mapping> <filter-name>session</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<dependency> <groupId>net.sourceforge.statelessfilter</groupId> <artifactId>stateless-core</artifactId> <version>0.8.4</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>net.sourceforge.statelessfilter</groupId> <artifactId>stateless-memcache</artifactId> <version>0.8.4</version> <exclusions> <exclusion> <groupId>spy</groupId> <artifactId>memcached</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>net.spy</groupId> <artifactId>spymemcached</artifactId> <version>2.12.0</version> </dependency> |
memcache.server1=192.168.14.132:11211
测试:
http://localhost:8080/test-stateless/test.do?username=javacoder.cn
工程地址
官网 http://statelessfilter.sourceforge.net
Posted in: WEB开发
Comments are closed.