Results 1 to 6 of 6

Thread: Spring AOP + Jsp

  1. #1
    Join Date
    Apr 2012
    Posts
    10

    Exclamation Spring AOP + Jsp

    Hi

    I have a strange question.

    Suppose you need to execute code really at the end of server interaction. So, if i use jsp, i need to execute it AFTER the rendering of the page.

    There is a way to execute it?

    i tried after this pointcut

    @Pointcut("@annotation(org.springframework.web.bin d.annotation.RequestMapping)")

    but it leave me just after the "return ModelAndView". I need to get the very end of the server session.

    Maybe it's absurd, but there is a way? Thanks anticipately

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Why?! But that is another question.

    Depending on what you need/want you could either write a HandlerInterceptor and implement the afterCompletion method (this is executed after rendering). If you really want to be sure you write a ServletRequestListener which will be executed before the request is handled and when the request is over.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2012
    Posts
    10

    Default

    Quote Originally Posted by Marten Deinum View Post
    Why?! But that is another question.

    Depending on what you need/want you could either write a HandlerInterceptor and implement the afterCompletion method (this is executed after rendering). If you really want to be sure you write a ServletRequestListener which will be executed before the request is handled and when the request is over.
    thank you, i implemented a ServletRequestListener. On the bad side, it lister for EVERY servlet, not only the @RequestMapping invoked servlet. Only for curiosity: afterCompletion is related only to the @RequestMapping annotated method? thanks

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I suggest a read of the reference guide, the section about HandlerInterceptors, that explains each method in detail and what the use of it is.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Apr 2012
    Posts
    10

    Default

    Sorry, i forgot to mention why: because i want to force closing all the database session, related to the running thread, that could possibly be not closed due to errors etc

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    To answer the why, that is why spring has transaction management etc. build in, simply use that instead of (re)inventing your own.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •