<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    姿姿霸霸~~!
    貴在堅持!
    posts - 106,  comments - 50,  trackbacks - 0
    今天做了個aop的試驗,對于springmvc的action不能攔截成功,研究了很久,沒有找到問題,所以請教下大家.
    下面是代碼:

    1.springmvc的action:
    package com.sure.demo.web;

    import java.util.Date;

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

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

    public class DemoTestAction extends MultiActionController {

        
    //返回的test頁面
        private String testPage;
      
        
    public String getTestPage() {
        
    return testPage;
        }


        
    public void setTestPage(String testPage) {
        
    this.testPage = testPage;
        }




        
    /**
         * test入口
         * 
    @param request
         * 
    @param response
         * 
    @return
         * 
    @throws Exception
         
    */

        
    public ModelAndView test(HttpServletRequest request,
            HttpServletResponse response) 
    throws Exception {
        ModelAndView mav 
    = null;
        mav 
    = new ModelAndView(this.getTestPage());
        request.setAttribute(
    "test"new Date().toString());
        
    return mav;
        }

        
    }

    2.jsp代碼:
    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%
    String test = (String)request.getAttribute("test");
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      
    <head>
     
      
    </head>
      
      
    <body>
        當(dāng)前時間是:
    <%=test %> <br>
      
    </body>
    </html>

    3.aop代碼:
    package com.sure.aopdemo;

    import org.aspectj.lang.JoinPoint;

    public class AopDemoTestImpl {

        
    public void afterTest(JoinPoint joinPoint) {
        System.out.println(
    "aop--執(zhí)行類:"+joinPoint.getThis()+""+joinPoint.getSignature().getName()+"方法之后");
        }


        
    public void beforeTest(JoinPoint joinPoint) {
        System.out.println(
    "aop--執(zhí)行類:"+joinPoint.getThis()+""+joinPoint.getSignature().getName()+"方法之前");
        }


        
    public void exceptionTest() {
        System.out.println(
    "aop方法異常");
        }


    }

    4.xml關(guān)于aop的配置:
    <?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:tx
    ="http://www.springframework.org/schema/tx"
             xsi:schemaLocation
    ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    >
        
        
    <bean id="aopDemoTestImpl" class="com.sure.aopdemo.AopDemoTestImpl"></bean>
        
        
    <aop:config>
            
    <aop:aspect id="test" ref="aopDemoTestImpl">
                
    <aop:pointcut id="a" expression="execution(* com.sure.demo..*.*(..))"/>
                
    <aop:before method="beforeTest" pointcut-ref="a"/>
                
    <aop:after method="afterTest" pointcut-ref="a"/>
                
    <aop:after-throwing method="exceptionTest" pointcut-ref="a"/>
            
    </aop:aspect>
        
    </aop:config>
        
    </beans>
    posted on 2008-09-22 23:19 xrzp 閱讀(7669) 評論(11)  編輯  收藏 所屬分類: JAVA

    FeedBack:
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-23 08:43 | toby941
    spring的Controller方法是不能AOP攔截的
    不是有專門的攔截器么  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-23 08:44 | 隔葉黃鶯
    你的 Action 要是通過 Spring IOC 容器創(chuàng)建的實例才能攔截到。  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-23 11:17 | sure_xx
    @隔葉黃鶯
    暈,我在配置文件里面,都寫了這些bean的.我發(fā)個郵件給你看哈.謝謝.  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-23 17:15 | 隔葉黃鶯
    application-context.xml 中的 aop 配置似乎影響不到 app-servlet.xml,他們不被同時解析處理的,試著把對 controller 的 aop 控制的配置移到 app-servlet.xml 中看看。  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-24 10:21 | 隔葉黃鶯
    用你發(fā)給我的代碼,執(zhí)行沒問題:

    訪問地址:
    http://localhost:8080/TestSpring2/demoTest.do?method=test

    頁面輸出:
    當(dāng)前時間是:Wed Sep 24 10:08:55 CST 2008
    gavin:抽煙中……

    控制臺輸出:
    aop--執(zhí)行類:com.sure.demo.biz.DemoTestBiz@1887735的testBiz方法之前
    執(zhí)行BIZ..
    aop--執(zhí)行類:com.sure.demo.dao.DemoTestDaoImpl@1fff293的testDao方法之前
    執(zhí)行DAO..testMap
    aop--執(zhí)行類:com.sure.demo.dao.DemoTestDaoImpl@1fff293的testDao方法之后
    aop--執(zhí)行類:com.sure.demo.biz.DemoTestBiz@1887735的testBiz方法之后

    你在日志中應(yīng)該要把問題描述清楚。  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-24 16:32 | sure_xx
    @隔葉黃鶯
    我的意思是沒有攔截到
    com.sure.demo.web.DemoTestAction 這個類里面的方法.控制臺輸出的都是攔截的biz和dao的信息  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-24 17:57 | 隔葉黃鶯
    從顯示那兩個對象來看,確實是 Spring Aop 沒有對 DemoTestAction 作特殊處理

    demoTestBiz
    (com.sure.demo.biz.DemoTestBiz$$EnhancerByCGLIB$$5a2f8a7b) com.sure.demo.biz.DemoTestBiz@6ffb14
    this
    (com.sure.demo.web.DemoTestAction) com.sure.demo.web.DemoTestAction@1155013  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-24 18:52 | 隔葉黃鶯
    spring mvc 的 HandlerMapping 有自己的 Interceptor,要實現(xiàn)接口 org.springframework.web.servlet.HandlerInterceptor,其中有 preHandle()、postHandle()、afterCompletion() 方法可監(jiān)視 action 的執(zhí)行,但在這幾個方法中能獲取到的信息不詳細(xì),但可以用來具體控制 Action 執(zhí)行前后的行為。假如這個攔截類是
    DemoActionHandlerInterceptor,這個實例需要配置給 HandlerMapping,配置方法如下:

    <bean id="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/demoTest.do">demoTest</prop>
    </props>
    </property>
    <property name="interceptors">
    <list>
    <bean class="com.sure.aopdemo.DemoActionHandlerInterceptor"/>
    </list>
    </property>
    </bean>  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!請教~~~~~~
    2008-09-24 19:49 | sure_xx
    @隔葉黃鶯
    謝謝黃鶯哈!問題解決了!就是像最后寫的那樣.自己寫一個繼承了HandlerInterceptor接口的類,然后再在里面重寫3個方法就能解決了.
    再次謝謝哈!  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!(已解決)
    2008-12-02 11:42 | 娃娃
    你成功的代碼能否發(fā)下出來啊?  回復(fù)  更多評論
      
    # re: aop攔截springmvc的action不成功!(已解決)
    2014-07-29 11:35 | sql吧
    樓主最后還有用攔截器的方式解決的??????
    spring mvc aop 不可以嗎??????  回復(fù)  更多評論
      

    <2008年9月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    常用鏈接

    留言簿(4)

    隨筆分類

    隨筆檔案

    好友的blog

    搜索

    •  

    積分與排名

    • 積分 - 117345
    • 排名 - 500

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲人成网站18禁止久久影院 | 黄色毛片免费在线观看| 国产成人精品日本亚洲11| 亚洲国产精品综合一区在线| 亚洲色欲色欲综合网站| 亚洲精品中文字幕无码AV| 亚洲欧洲国产成人精品| 亚洲国产成人精品青青草原| 久久精品国产亚洲AV蜜臀色欲 | 亚洲一卡2卡3卡4卡乱码 在线| 亚洲人成电影在线观看网| 亚洲精品在线视频观看| 亚洲人成网站日本片| 亚洲人成电影网站免费| 亚洲风情亚Aⅴ在线发布| 在线亚洲v日韩v| www在线观看免费视频| 免费在线黄色电影| 日日麻批免费40分钟无码 | 黄网站色成年片大免费高清| 国产黄在线播放免费观看| 中国在线观看免费的www| 久久久免费的精品| 91网站免费观看| 性色av免费观看| 高清在线亚洲精品国产二区| 国产精品亚洲高清一区二区| 亚洲av日韩av激情亚洲| 亚洲国产成人久久77| 亚洲aⅴ无码专区在线观看春色| 日本激情猛烈在线看免费观看 | 久久久久久噜噜精品免费直播 | 国产亚洲视频在线| 久久久久久久国产免费看| 97在线视频免费公开观看| 女性无套免费网站在线看| 亚洲欧洲国产成人综合在线观看 | 亚洲欧洲精品在线| 白白色免费在线视频| 最近免费mv在线观看动漫| 91免费国产在线观看|