struts2配置自定义拦截器
来源:互联网 发布:淘宝网衣服女裤 编辑:程序博客网 时间:2024/05/22 01:47
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts><package name="UserAction" extends="struts-default" namespace="/"><!-- 【拦截器配置】 --><interceptors><interceptor name="loginCheck" class="com.hyxd.Interceptor.UserCheckInterceptor"></interceptor><interceptor-stack name="myStack"><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="loginCheck"></interceptor-ref></interceptor-stack></interceptors><!-- 【执行拦截器:第一种写法: 当前包下所有的acntion都执行myStack栈】<default-interceptor-ref name="myStack"></default-interceptor-ref>--><!-- 全局定义 --><global-results><result name="error">/error.jsp</result><result name="input">/login.jsp</result></global-results><!-- 第一个action --><action name="user_*" class="com.hyxd.action.UserAction" method="{1}"><!-- redirectAction 不会保留request对象 --><result type="redirectAction" name="{1}">emp_list</result> </action><!-- 第二个action 接收redirectAction(重定向到新的Action)value=emp_list--><action name="emp_*" class="com.hyxd.action.EmployeeAction" method="{1}"><!--第二种写法: 只是在这一个Action中执行myStack栈 <interceptor-ref name="defaultStackt"></interceptor-ref><interceptor-ref name="loginCheck"></interceptor-ref>--><!-- 第三种写法:执行用户栈(与第二种写法一样, 只在当前aciton中执行自定义栈) --><interceptor-ref name="myStack"></interceptor-ref><result name="{1}">/WEB-INF/list.jsp</result> </action></package></struts>
自定义拦截器
package com.hyxd.Interceptor;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.ActionProxy;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class UserCheckInterceptor extends AbstractInterceptor{@Overridepublic String intercept(ActionInvocation invocation) throws Exception {//获取ActionContext对象ActionContext ac = invocation.getInvocationContext();// 获取action的代理对象ActionProxy proxy = invocation.getProxy();//得到代理对象正在运行的方法名String methodName = proxy.getMethod();if(!"login".endsWith(methodName)){//从session中获取用户名Object obj = ac.getSession().get("userInfo");if(obj==null){return "input";}else{return invocation.invoke();}}else{return invocation.invoke();}}}
0 0
- struts2配置自定义拦截器
- 如何配置自定义struts2拦截器
- Struts2 自定义拦截器配置和使用
- struts2自定义拦截器注解配置方法
- struts2的自定义拦截器和配置
- struts2中自定义拦截器的配置
- struts2 自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- Struts2---自定义拦截器
- struts2自定义拦截器
- struts2自定义拦截器
- 积累
- QT4 支持C++11 与QT5的区别
- 测试风险评估
- opencv的cornerHarris函数
- java多线程中的关键字volatile
- struts2配置自定义拦截器
- android ROM设置默认Launcher(主屏幕应用)
- ubuntu 利用crosstool-ng-1.8.1制作交叉编译工具链
- 拦截器集中处理小程序request请求
- Mac 配置Tomcat 8.5.11
- Java 接口和抽象类
- MFC程序命令行输出printf信息
- Linux常用命令介绍。转载自http://blog.csdn.net/suwu150
- 《ACM程序设计》书中题目O-15