struts2 使用oscache

在web.xml里增加如下内容:

<filter>  
        <filter-name>CacheFilter</filter-name>  
        <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>  
    </filter>  
  
    <filter>  
        <filter-name>CacheFilter-disableCacheOnMethods</filter-name>  
        <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>  
        <init-param>  
            <param-name>time</param-name>  
            <param-value>60</param-value>  
        </init-param>  
        <init-param>  
            <param-name>disableCacheOnMethods</param-name>  
            <param-value>POST,PUT,DELETE</param-value>  
        </init-param>  
        <init-param>  
            <param-name>oscache-properties-file</param-name>  
            <param-value>/oscache-cachefilter-disableCacheOnMethods.properties</param-value>  
        </init-param>  
    </filter>  

 

 

这个一定要放到 struts2的filtermapping之前,要不可就先执行struts2的   

 

<filter-mapping>  
        <filter-name>CacheFilter</filter-name>  
        <url-pattern>/xx/*</url-pattern>  
    </filter-mapping>  

   

 

把oscache.jar放到WEB-INF/lib下,把相关property和tld放到src根目录下。

ok。

/xx/路径下的页面都可以缓存了。有一点要注意 /xx/xx.action?url=1 和/xx/xx.action?url=2是不同的。

你可能感兴趣的:(Web,xml)