May 25th, 2012, 04:32 AM
Updating HTML body content using Spring interceptors
I'm using Spring MVC 3.0.5 version and am making use of HandlerInterceptor. I have a controller which point to a particular ModelAndView pointing to the jsp say home.jsp. However in certain cases i need to append some HTML section into the body of the home.jsp.
I'm planning to override the postHandle method of the Interceptor, where i would need to append the HTML section into the response OutputStream.
Just wanted to check if this implementation is the right one?
May 25th, 2012, 05:18 AM
No it isn't. As nothing has been written also not sure if that is the best approach, writing your own html in general is ill advised. In general I would suggest a templating approach or some conditional logic in your jsp (the first option is preferred as you should avoid too much logic in your jsps).
May 25th, 2012, 07:35 AM
Thanks for your reply. The problem is the jsp's are not in my control and what we're doing is that we have a sort of a generic controller which gets called to return ModelAndView of different jsp's.
Originally Posted by Marten Deinum
The use case is that in the home.jsp, on clicking on a link, a pop-up is shown which displays the content which is fetched from another jsp.
So we're trying to basically mimic the same pop-up behavior on load of the home.jsp, by trying to inject the required html block to the response.
May 25th, 2012, 07:41 AM
You could try a filter and include something in your response (which is also how SiteMesh works) but manipulating jsps in such a way in general I would recommend against it.
Tags for this Thread