• Struts2拦截器的应用


     拦截器类

    public class AdminInterceptor extends AbstractInterceptor { 
        private static final long serialVersionUID = 1L; 
        //管理员操作相关的拦截器 
        @Override 
        public String intercept(ActionInvocation invocation) throws Exception { 
            String result = null; 
            ActionContext actionContext = invocation.getInvocationContext(); 
            if((actionContext.getSession().get("admin")==null||"".equals(actionContext.getSession().get("admin")))){ 
                return "admin_login"; 
            } 
            result = invocation.invoke(); 
            return result; 
        } 
        public static void main(String[] args) { 
            // TODO Auto-generated method stub 
        } 
    } 

    admin.xml中应用

    <?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="admin" extends="struts-default"> 
            <interceptors> 
                <interceptor name="AdminInterceptor" class="com.umgsai.txyl.interceptor.AdminInterceptor" /> 
                <!-- 定义拦截器栈 --> 
                <interceptor-stack name="myStack"><!-- 引用自定义拦截器进行身份验证 --> 
                    <interceptor-ref name="defaultStack" /> 
                    <interceptor-ref name="AdminInterceptor" /> 
                </interceptor-stack> 
            </interceptors> 
            <default-interceptor-ref name="myStack" /><!--拦截器引用 -->          
            <global-results><!-- 全局结果转发 -->              
                <result name="admin_login">/admin/login.jsp</result><!-- 管理员身份验证失败 --> 
            </global-results> 
            <action name="image_upload" class="com.umgsai.txyl.action.UploadAction" method="site_modify"> 
                <param name="allowTypes">image/bmp,image/png,image/gif,image/jpeg,image/pjpeg</param> 
                <param name="savePath">/images</param> 
                <result name="error">site_modify.jsp?site_id=${site_id}</result> 
                <result name="success">site_modify.jsp?site_id=${site_id}</result> 
            </action>          
            <action name="admin_login" class="com.umgsai.txyl.action.AdminAction" 
                method="execute"> 
                <interceptor-ref name="defaultStack"/> 
                <result name="admin_login_success">index.jsp</result><!-- //用户登录 --> 
                <result name="admin_login_failed">login.jsp</result> 
            </action> 
        </package>  
    </struts> 
  • 相关阅读:
    [super dealloc]内存释放的先后顺序
    NSString的常用方法
    Xcode开发技巧之code snippets(代码片段)
    关于oc运行时 isa指针详解
    ios快捷键
    自动释放池的使用
    【字典树】统计难题
    数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
    字典树模板
    数据结构实验之串三:KMP应用
  • 原文地址:https://www.cnblogs.com/umgsai/p/3908124.html
Copyright © 2020-2023  润新知