Apr 20th, 2012, 09:23 AM
Spring AOP + Jsp
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
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
Apr 23rd, 2012, 01:21 AM
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.
Apr 23rd, 2012, 09:01 AM
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
Originally Posted by Marten Deinum
Apr 23rd, 2012, 09:06 AM
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.
Apr 23rd, 2012, 09:14 AM
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
Apr 23rd, 2012, 09:17 AM
To answer the why, that is why spring has transaction management etc. build in, simply use that instead of (re)inventing your own.