zoukankan      html  css  js  c++  java
  • Struct2 自定义拦截器

    1 因为struct2 如文件上传,数据验证等功能都是由系统默认的
    defalutStack中的拦截器实现的,所以我们定义拦截器需要引用系统默认的defalutStack
    这样才不会影响struct2在的其它功能
    struts.xml
     <package name="base" namespace="/hello" extends="struts-default">
        <interceptors>
        <interceptor name="permission" class="cn.itcast.Interceptor.PermissionInterceptor" />
       <interceptor-stack name="permissionStack">
       <interceptor-ref name="defaultStack" />
       <interceptor-ref name="permission" />
       </interceptor-stack>
        </interceptors>
        <global-results >
    <result name="success">/WEB-INF/page/message.jsp</result>
        </global-results>
        <action name="list_*" class="cn.itcast.action.HelloWorldAction" method="{1}" >
    <interceptor-ref name="permission" />
         </action>
     </package>
    //访问list_* 该方法时就会调用到PermissionInterceptor 这个拦截器
    PermissionInterceptor.java


    public String intercept(ActionInvocation invocation) throws Exception {
    Object user = ActionContext.getContext().getSession().get("user");
    if(user != null) return invocation.invoke();
    ActionContext.getContext().put("message","你没有执行该方法的权限");
    return "success";
    }
  • 相关阅读:
    os模块
    random模块
    datetime模块
    time模块
    软甲开发目录规范
    模块与包
    函数递归
    内置函数
    【NOIP2016提高组】换教室
    【NOIP2015提高组】运输计划
  • 原文地址:https://www.cnblogs.com/sandea/p/3520830.html
Copyright © 2011-2022 走看看