(转)实现struts2的CRUD中的权限控制(二)
在《 实现struts2的CRUD中的权限控制》这篇文章中,我提了一个问题,就是说在自己实现了权限拦截器后,每个action都要配置拦截器后才可以在调用他后进行权限检查,今天看了一下资料,可以设定默认的拦截器,在没有显示设定拦截器时就会使用默认拦截器,达到该目的,以后该package中的方法都会使用默认的“权限拦截器”,示例配置文件如下:
上面得配置中大家可以看到我们使用了全局result也是基于要解决像每个action都要配置拦截器一样的重复问题,其实全局result也就是为了减少重复,回过头来看,默认拦截器是不是也可以全局拦截器呢,有这样的味道,呵呵...
<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>
<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>