自定义拦截器的步骤

来源:互联网 发布:sql重命名列名 编辑:程序博客网 时间:2024/06/01 10:39
自定义拦截器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


0 0
原创粉丝点击