MayurKode
MayurKode

Reputation: 135

Need to pass value from interceptor to handller in spring

Hey I am new to spring and I need help on below: I have interceptor with prehandle and posthandle mehtods in it.I want to send some values to handller from interceptor.

suggest any idea.

Thanks.

Upvotes: 1

Views: 1340

Answers (2)

Prasad
Prasad

Reputation: 3795

You can achieve this as: In your interceptor prehandle method:

    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
            ...
            HttpSession session = request.getSession();
            session.setAttribute("attributeName", objectYouWantToPassToHandler);
            ....
            }

In your handler handleRequest method:

   public ModelAndView handleRequest(HttpServletRequest request,
        HttpServletResponse response) throws Exception {                

        ....
        HttpSession session = request.getSession();
        objectYouWantToPassToHandler objectYouWantToPassToHandler = session.getAttribute("attributeName");
        ....
        }

Upvotes: 1

Artem Bilan
Artem Bilan

Reputation: 121427

Actually, your question ins't clear, sorry. Try start from Spring AOP

And, of course, you have to show your code: what you have and what you want to do.

Upvotes: 0

Related Questions