tags:

views:

52

answers:

1

Currently I am using request.setAttribute() and request.getAttribute() as a means to pass an object from a handler interceptor to a controller method. I don't view this as an ideal technique, because it requires that I take HttpServletRequest as an argument to my controller methods. Spring does a good job hiding the request object from controllers, so I would not need it except for this purpose.

I tried using the @RequestParam annotation with the name I set in setAttribute(), but of course that did not work because request attributes are not request params. To my knowledge, there is no @RequestAttribute annotation to use for attributes.

My question is, is there some better way to hand off objects from interceptors to controller methods without resorting to setting them as attributes on the request object?

A: 

I don't think there is.

But you could roll your own @RequestAttribute annotation. See http://stackoverflow.com/questions/1263941/spring-mvc-annotation-requestattribute-similar-to-requestparam for a similar question and link to the source.

david
If I were to add a custom @RequestAttribute, how might I go about making that work in Spring? How does Spring know what to do with it?
JamesH