實現struts2的CRUD中的許可權控制(二)

來源:互聯網
上載者:User
      在《 實現struts2的CRUD中的許可權控制》這篇文章中,我提了一個問題,就是說在自己實現了許可權攔截器後,每個action都要配置攔截器後才可以在調用他後進行許可權檢查,今天看了一下資料,可以設定預設的攔截器,在沒有顯示設定攔截器時就會使用預設攔截器,達到該目的,以後該package中的方法都會使用預設的“許可權攔截器”,樣本設定檔如下:
       

<package name="admin" extends="struts-default" namespace="/admin">
        <interceptors>
            <interceptor name="auth"
                class="com.waimai.utils.AuthorizationInterceptor" />
        </interceptors>

        <default-interceptor-ref name="auth" />


        <global-results>
            <result name="login" type="redirect">
                /security/login.jsp
            </result>
        </global-results>

        <action name="List" class="com.waimai.web.CaiTypeAction"
            method="list">

            <result>listCaiType.jsp</result>
        </action>
        <action name="Edit" class="com.waimai.web.CaiTypeAction"
            method="load">

            <result>editCaiType.jsp</result>
        </action>
        <action name="Store" class="com.waimai.web.CaiTypeAction"
            method="store">

            <result name="input" type="dispatcher">
                editCaiType.jsp
            </result>
            <result type="redirect">List.action</result>
        </action>
        <action name="Remove" class="com.waimai.web.CaiTypeAction"
            method="remove">

            <result type="redirect">List.action</result>
        </action>
    </package>

      上面得配置中大家可以看到我們使用了全域result也是基於要解決像每個action都要配置攔截器一樣的重複問題,其實全域result也就是為了減少重複,回過頭來看,預設攔截器是不是也可以全域攔截器呢,有這樣的味道,呵呵...
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.