姿姿霸霸~~!
贵在坚持!
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>
    当前时间是:
<%=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--执行类:"+joinPoint.getThis()+""+joinPoint.getSignature().getName()+"方法之后");
    }


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


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


}

4.xml关于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"