首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

自定义Interceptor后取得Session对象

2012-09-19 
自定义Interceptor后获得Session对象自定义拦截器的时候 主要分为 三步1.定义拦截器类 重要的是要继承 Abs

自定义Interceptor后获得Session对象
自定义拦截器的时候 主要分为 三步

1.定义拦截器类 重要的是要继承 AbstractInterceptro 类 重写里面的 intercept(ActionInvocation   actionInvocation) 方法

    另外注意  其中得到session 对象的方法

    ActionContext  ac = actionInvocation.getInvocationContext();

    Map<String,Object> session = ac .getSession();

2.在struts2 的配置文件中 struts2.xml  文件中声明配置 intercepor

<package name="default" extends="struts-default" namespace="/">

    <!--声明拦截器-->

    <interceptor name="LoginInterceptor" class="com.ztf.action.UserAction">

       <!--在Action中引用拦截器-->

        <intercepor-ref>LoginInterceptor</interceptor-ref>

        <result name="success">/showUser.jsp</result>

    </action>

</package>

热点排行