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

          有關于Spring攔截器

          Posted on 2006-12-02 15:15 碼農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類實現preHandle方法。這是在controller調用業務邏輯方法前調用這個方法。

          ?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?

          這樣就算配置好了。
          在前臺頁面調用的時候這個攔截器會對提交進行攔截!
          ok , enjoy it!

          評論

          # re: 有關于Spring攔截器  回復  更多評論   

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

          # re: 有關于Spring攔截器  回復  更多評論   

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

          # re: 有關于Spring攔截器[未登錄]  回復  更多評論   

          2010-01-26 17:31 by dd
          asd

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


          網站導航:
           
          主站蜘蛛池模板: 环江| 岗巴县| 都昌县| 临澧县| 周口市| 土默特右旗| 额尔古纳市| 松潘县| 左云县| 西平县| 邹城市| 从江县| 麦盖提县| 鄂托克前旗| 海伦市| 清水河县| 浮山县| 仁布县| 康定县| 绥芬河市| 达尔| 郑州市| 沙河市| 色达县| 新民市| 赤壁市| 阿拉善左旗| 巧家县| 彩票| 武城县| 定结县| 新宾| 浑源县| 阿城市| 民县| 孙吴县| 沭阳县| 扎鲁特旗| 和林格尔县| 吴江市| 临猗县|