posts - 22, comments - 17, trackbacks - 0, articles - 15
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          有關(guān)于Spring攔截器

          Posted on 2006-12-02 15:15 碼農(nóng)cz 閱讀(1388) 評論(3)  編輯  收藏

          SpringWeb中攔截器的配置與使用
          ???在xxx-servlet.xml中
          ???

          ?1 < bean? id ="urlMapping"
          ?2 ????????class ="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
          ?3 ???????? < property? name ="mappings" >
          ?4 ???????????? < value >
          ?5 ???????????????? <!-- ?AppTemplate? -->
          ?6 ????????????????/**/AppTemplate.wc=AppTemplateController
          ?7 ???????????? </ value >
          ?8 ???????? </ property >
          ?9 ???? <!-- start?interceptors? -->
          10 ???????? < property? name ="interceptors" >
          11 ???????????? < list >
          12 ???????????????? < ref? bean ="testInterceptors" />
          13 ???????????? </ list >
          14 ???????? </ property >
          15 ???? </ bean >
          16 ???? <!-- ?interceptors?beans -->
          17 ???? < bean? id ="testInterceptors" ?class ="net.interceptors.TestInterceptors" >
          18 ???? </ bean >

          <!--start interceptors -->配置urlmaping的屬性interceptors它的<ref bean>是自己寫的。只需要繼承HandlerInterceptorAdapter類實(shí)現(xiàn)preHandle方法。這是在controller調(diào)用業(yè)務(wù)邏輯方法前調(diào)用這個(gè)方法。

          ?1?public?class?TestInterceptors?extends?HandlerInterceptorAdapter?{
          ?2?????public?boolean?preHandle(HttpServletRequest?request,?HttpServletResponse?response,?Object?handler)?throws?Exception?{
          ?3?????????Person?person?=?new?Person();
          ?4?????????BeanUtil.load(person,?request);
          ?5?????????if(person.getUserName().equalsIgnoreCase("cz")){
          ?6?????????????return?true;
          ?7?????????}else{
          ?8?????????????response.sendRedirect("http://www.baidu.com");
          ?9?????????????return?false;
          10?????????}
          11?????????????
          12?????}
          13?}
          14?

          這樣就算配置好了。
          在前臺頁面調(diào)用的時(shí)候這個(gè)攔截器會(huì)對提交進(jìn)行攔截!
          ok , enjoy it!

          評論

          # re: 有關(guān)于Spring攔截器  回復(fù)  更多評論   

          2008-06-16 16:34 by diorchina
          < property name ="mappings" > 里寫什么

          # re: 有關(guān)于Spring攔截器  回復(fù)  更多評論   

          2008-06-19 09:18 by czcoding
          @diorchina
          < value >
          <!-- AppTemplate -->
          /**/AppTemplate.wc=AppTemplateController
          </ value >

          # re: 有關(guān)于Spring攔截器[未登錄]  回復(fù)  更多評論   

          2010-01-26 17:31 by dd
          asd

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 江油市| 县级市| 和田县| 渭源县| 三门峡市| 永寿县| 开原市| 黄陵县| 兴仁县| 盈江县| 彰武县| 梁山县| 鄱阳县| 安徽省| 新宁县| 兴义市| 进贤县| 赤壁市| 廉江市| 安丘市| 镇赉县| 河东区| 水城县| 许昌市| 凤阳县| 五峰| 武隆县| 南康市| 宣化县| 龙里县| 涟水县| 麻栗坡县| 桦川县| 惠东县| 洛南县| 五台县| 高唐县| 宕昌县| 天柱县| 鄂温| 司法|