zoukankan      html  css  js  c++  java
  • Struts2-lesson4

    登陆练习

    <interceptors>
        <!-- 注册拦截器 -->
        <interceptor name="loginInterceptor"
            class="cn.itheima.web.interceptor.LoginInterceptor"></interceptor>
    
        <!-- 注册拦截器栈 -->
        <interceptor-stack name="myStack">
            <interceptor-ref name="loginInterceptor">
                <param name="excludeMethods">login</param>
            </interceptor-ref>
            <interceptor-ref name="defaultStack"></interceptor-ref>
        </interceptor-stack>
        <!-- -->
    </interceptors>
    <!-- 指定包中的默认拦截器栈 -->
    <default-interceptor-ref name="myStack"></default-interceptor-ref>

    http://localhost:8080/test_struts2/login.jsp

    自定义拦截器

    (需要先登陆再进行case测试)

    配置拦截器讲究书写格式/顺序

    <package name="hello" namespace="/hello" extends="struts-default">
            <!-- -->
            <interceptors>
                <!-- 注册拦截器 -->
                <interceptor name="loginInterceptor"
                    class="cn.itheima.web.interceptor.LoginInterceptor"></interceptor>
                <!-- 
                <interceptor name="myInter1"
                    class="cn.itcast.a_interceptor.MyInterceptor"></interceptor>
                <interceptor name="myInter2"
                    class="cn.itcast.a_interceptor.MyInterceptor2"></interceptor>
                 -->
                <interceptor name="myInter3"
                    class="cn.itcast.a_interceptor.MyInterceptor3"></interceptor>
                
                <!-- 注册拦截器栈   注意顺序 -->
                <interceptor-stack name="myStack">
                
                    <!-- 自定义拦截器引入(建议放在20个拦截器之前) -->
                    <interceptor-ref name="loginInterceptor">
                        <param name="excludeMethods">login</param>
                    </interceptor-ref>
                    <!-- 
                    <interceptor-ref name="myInter1">
                        <param name="includeMethods">execute,add,delete</param>
                    </interceptor-ref>
                    <interceptor-ref name="myInter2">
                        <param name="includeMethods">execute,add,delete</param>
                    </interceptor-ref>
                     -->
                    
                    <interceptor-ref name="myInter3">
                        <!-- 指定哪些方法不拦截 <param name="excludeMethods">add,delete</param> -->
                        <!-- 指定哪些方法需要拦截 -->
                        <param name="includeMethods">add,delete</param>
                    </interceptor-ref>
                    <interceptor-ref name="defaultStack"></interceptor-ref>
                    
                </interceptor-stack>
                
            </interceptors>
            
            <!-- 指定包中的默认拦截器栈 -->
            <default-interceptor-ref name="myStack"></default-interceptor-ref>
            
            <!-- 定义全局结果集 练习中的case必须要登陆! -->
            <global-results>
                <result name="toLogin" type="redirect">/login.jsp</result>
            </global-results>
    
    
            <global-exception-mappings>
                <!-- 如果出现java.lang.RuntimeException异常,就将跳转到名为error的结果 -->
                <exception-mapping result="error"
                    exception="java.lang.RuntimeException"></exception-mapping>
            </global-exception-mappings>
            
                    <!-- 第四课 -->
            <action name="UserAction_*" class="cn.itheima.web.action.UserAction"
                method="{1}">
                <result name="toHome" type="redirect">/index.htm</result>
                <result name="error">/login.jsp</result>
            </action>
            <action name="D4Demo1Action_*" class="cn.itcast.a_interceptor.D4Demo1Action"
                method="{1}">
                <!-- 为Action单独指定走哪个拦截器(栈) <interceptor-ref name="myStack"></interceptor-ref> -->
                <result name="success" type="dispatcher">/dx.jsp</result>
            </action>
        </package>

    http://localhost:8080/test_struts2/hello/D4Demo1Action.action

    http://localhost:8080/test_struts2/hello/D4Demo1Action_add.action

    http://localhost:8080/test_struts2/hello/D4Demo1Action_update.action

    (拦截器的意义,是拦截后端action请求进而在过程中做手脚的,区别过滤器与监听器)

    Struts2标签

    http://localhost:8080/test_struts2/D4Demo2Action.action

    http://localhost:8080/test_struts2/tag2.jsp

    http://localhost:8080/test_struts2/D4Demo3Action.action

    击石乃有火,不击元无烟!!
  • 相关阅读:
    插入排序的Python代码实现
    数据结构基础--二叉堆、优先队列
    数据结构基础--二叉树
    数据结构基础--数组、链表、栈、队列、哈希表
    转:数据结构与算法系列--十大排序(附动态图解
    快速排序的Python代码实现
    选择排序的Python代码实现
    csv文件的读取写法 from Udacity
    Linux下测试ZLAN 5800
    冒泡排序的Python代码实现
  • 原文地址:https://www.cnblogs.com/rain2020/p/12799331.html
Copyright © 2011-2022 走看看