您的位置:首页 > 其它

自定义拦截器的步骤

2016-05-14 17:54 267 查看
自定义拦截器

1). 具体步骤

I. 定义一个拦截器的类
有两种方式:
方式一: 可以实现 Interceptor 接口
方式二: 继承 AbstractInterceptor 抽象类

II. 在 struts.xml 文件配置.

<interceptors>

<interceptor name="hello" class="com.atguigu.struts2.interceptors.MyInterceptor"></interceptor>

</interceptors>

<action name="testToken" class="com.atguigu.struts2.token.app.TokenAction">
<interceptor-ref name="hello"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/success.jsp</result>
<result name="invalid.token">/token-error.jsp</result>
</action>

III. 注意: 在自定义的拦截器中可以选择不调用 ActionInvocation 的 invoke() 方法. 那么后续的拦截器和 Action 方法将不会被调用.
Struts 会渲染自定义拦截器 intercept 方法返回值对应的 result
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: