一杯清茶

          統計

          留言簿

          Oracle SQL/PLSQL

          PowerDesigner教程系列

          Struts2.0

          web開發

          三人行

          從事RCP開發的同行

          工作流和權限設置

          閱讀排行榜

          評論排行榜

          Spring攔截器來控制URL路徑的轉發

           
          struts的代碼 
          1. import javax.servlet.http.HttpServletRequest;   
          2. import org.aopalliance.intercept.MethodInterceptor;   
          3. import org.aopalliance.intercept.MethodInvocation;   
          4. import org.apache.struts.action.ActionMapping;   
          5.   
          6. /**  
          7.  * 這是一個攔截器,用來驗證用戶是否通過驗證  
          8.  *  
          9.  */  
          10. public class AuthorityInterceptor implements MethodInterceptor {   
          11.   
          12.     public Object invoke(MethodInvocation invocation) throws Throwable   
          13.     {   
          14.         HttpServletRequest request = null;   
          15.         ActionMapping mapping = null;   
          16.         Object[] args = invocation.getArguments();   
          17.         for (int i = 0 ; i < args.length ; i++ )   
          18.         {   
          19.             if (args[i] instanceof HttpServletRequest) request = (HttpServletRequest)args[i];   
          20.             if (args[i] instanceof ActionMapping) mapping = (ActionMapping)args[i];   
          21.         }   
          22.         if ( request.getSession().getAttribute("adminname") != null)   
          23.         {   
          24.             return invocation.proceed();   
          25.         }   
          26.         else  
          27.         {   
          28.             return mapping.findForward("login");   
          29.         }   
          30.     }   
          31. }  


          配置文件:
          Java代碼
          1.    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">   
          2.     <property name="beanNames">   
          3.            <list>   
          4.               <value>/vaiiduser</value>   
          5.                <value>/admin</value>   
          6.               <value>/phone</value>   
          7.            </list>   
          8.     </property>   
          9.        <property name="interceptorNames">   
          10.            <list>   
          11.                <value>authorityInterceptor</value>    
          12.            </list>   
          13.        </property>   
          14.    </bean>   
          15.   
          16. <bean id="authorityInterceptor" class="org.mmc.utils.AuthorityInterceptor"/>

          posted on 2009-10-27 09:22 一杯清茶 閱讀(3860) 評論(0)  編輯  收藏 所屬分類: Spring

          主站蜘蛛池模板: 台南市| 白玉县| 芮城县| 阿拉尔市| 泾川县| 应用必备| 江陵县| 翼城县| 津市市| 丘北县| 根河市| 当涂县| 威远县| 道孚县| 安塞县| 吴旗县| 甘德县| 科技| 横山县| 贵州省| 明光市| 凌源市| 新巴尔虎左旗| 锡林浩特市| 兴宁市| 揭东县| 绍兴市| 天等县| 宣化县| 昭苏县| 岳西县| 衡山县| 台湾省| 德江县| 航空| 正蓝旗| 石狮市| 年辖:市辖区| 海口市| 定兴县| 家居|