備注學(xué)院

          LuLu

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            5 隨筆 :: 50 文章 :: 16 評論 :: 0 Trackbacks
          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 2008-01-31 19:40 smildlzj 閱讀(2343) 評論(0)  編輯  收藏 所屬分類: Web開發(fā)
          主站蜘蛛池模板: 通山县| 礼泉县| 张家港市| 宁化县| 紫阳县| 金华市| 汉阴县| 娱乐| 栾城县| 突泉县| 英吉沙县| 通化市| 樟树市| 固镇县| 盘锦市| 靖远县| 清苑县| 乡城县| 青川县| 夏邑县| 昌平区| 蒙山县| 福鼎市| 洪洞县| 安阳市| 高台县| 永吉县| 磐石市| 渝中区| 房产| 呼和浩特市| 盐津县| 稷山县| 闵行区| 普兰店市| 克山县| 建昌县| 滦南县| 陇西县| 察隅县| 察雅县|