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";
    }
  • 相关阅读:
    AC_9. 分组背包问题
    AC_8. 二维费用的背包问题
    AC_7混合背包问题
    AC_5. 多重背包问题 II
    AC_4. 多重背包问题 I
    AC_3. 完全背包问题
    小郡肝火锅点餐系统——测试部署发布
    Vue脚手架搭建
    归并排序-总结
    小郡肝火锅点餐系统——项目文档
  • 原文地址:https://www.cnblogs.com/sandea/p/3520830.html
Copyright © 2011-2022 走看看