Struts2.0的IOC方式注入SessionAware, CookiesAware

在Action实现相应的 

private Map<String, Object> session;

 private Map<Object, Object> cookies;

的setter。getter方法。

 

 

在struts。xml配置如下Cookie的拦截器:

 

如下:

 <package name="default" extends="struts-default">
  <interceptors>
    <interceptor name="cookieInterceptor" class="org.apache.struts2.interceptor.CookieInterceptor">
     <param name="cookiesName">default_use_query_type_cookie</param> //拦截器名称
    </interceptor>
   
    <interceptor-stack name="globalInterceptorStack">
     <interceptor-ref name="cookieInterceptor"></interceptor-ref>
     <interceptor-ref name="paramsPrepareParamsStack"></interceptor-ref>
    </interceptor-stack>
  </interceptors>
  <default-interceptor-ref name="globalInterceptorStack"/>
 </package>

 

实现Cookie,Session的自动注入。

你可能感兴趣的:(apache,xml,struts,IOC)