Announcement Announcement Module
Collapse
No announcement yet.
How to get the HttpServletResponse object in the around advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get the HttpServletResponse object in the around advice

    Code:
    @Component
    @Aspect
    public class SpringAspect {
        @Around("execution(* cn.luna.web.controller.*.*(..))")
        public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
            Method method=((MethodSignature)pjp.getSignature()).getMethod();
            //Here I wanna get the HttpServletRequest request and the HttpServletReponse response,I don't know how to do.
            System.out.println("enter the method:"+method);
            Object result = pjp.proceed();
            System.out.println("exit the method");
            return result;
        }
    }
    I use spring mvc to develop my project.

    Thanks for help!!

  • #2
    I was looking for the same thing... I found the solution in this other topic: http://forum.springsource.org/showth...-inside-aspect

    Code:
    //ServletRequestAttributes may be null, check it first.
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Kind regards.

    Comment

    Working...
    X