沉睡森林@漂在北京

          本處文章除注明“轉(zhuǎn)載”外均為原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            152 隨筆 :: 4 文章 :: 114 評(píng)論 :: 0 Trackbacks
          利用攔截器對(duì)spring的controller進(jìn)行了攔截,實(shí)現(xiàn)代碼如下:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:aop
          ="http://www.springframework.org/schema/aop" 
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xmlns:context
          ="http://www.springframework.org/schema/context"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
              http://www.springframework.org/schema/aop
                 http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context-2.5.xsd"
          >
              
          <context:component-scan base-package="com.example" />
              
          <bean id="handlerMappingTemplate" abstract="true">
                  
          <property name="interceptors">
                      
          <list>
                          
          <bean class="com.example.aspect.LoginCheckInterceptor" />
                      
          </list>
                  
          </property>
              
          </bean>
              
          <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" parent="handlerMappingTemplate" />
              
          <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" parent="handlerMappingTemplate" />
              
          <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
              
          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/app/" p:suffix=".jsp" />
          </beans>

          具體的java類代碼也比較簡(jiǎn)單
          package com.example.aspect;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


          public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

              @Override
              
          public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
                  
                  System.out.println(
          "\n\n\n\n\n"+request);
                  
          throw new Exception("用戶沒有該操作的權(quán)限!");
              }
              

          }

          posted on 2009-02-20 15:07 王總兵 閱讀(4452) 評(píng)論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 镇巴县| 临沂市| 德格县| 贵德县| 银川市| 上高县| 名山县| 晋州市| 菏泽市| 长宁县| 西昌市| 崇州市| 峨边| 民勤县| 酉阳| 红河县| 革吉县| 化州市| 大理市| 靖安县| 洪洞县| 黑山县| 乌拉特前旗| 咸丰县| 天全县| 孝义市| 井研县| 凉城县| 南川市| 额敏县| 大田县| 阳江市| 墨玉县| 四子王旗| 聂拉木县| 前郭尔| 屏东市| 岱山县| 临泉县| 富阳市| 普陀区|