tags:

views:

357

answers:

1

Hi. I would like to access an HttpServletRequest object of the originating request in a custom InternalResourceViewResolver based resolver. Is there any simple way to do this? I am using Spring 2.5 here.

+5  A: 

The ViewResolver interface is not supplied with the current request, and so neither do the implementations of it .

However, you do have the option of fetching the current request from the RequestContextHolder, which uses thread-bound variables to store things like the request, but it's not pretty:

((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
skaffman
Thanks a lot. This does the trick. Any side effects of this technique I should be aware of?
Not side-effects per se, but be aware that the context holder is initialized by DispatcherServlet. As long as your requests pass through that, then you should be fine as long as you don't start doing saucy things with background threading.
skaffman