R. S.
R. S.

Reputation: 400

Add Extra parameter to HttpServletRequest

Is there is any way to add parameter to request object in spring 4,

like

public Map<String,Object> myMethod(HttpServletRequest request){
      request.setParameter("myKey", "myValue"); // It dont have this kind of method
}

Any help will be appreciated

Upvotes: 1

Views: 4983

Answers (1)

Udo Klimaschewski
Udo Klimaschewski

Reputation: 5315

The HttpServletRequestobject cannot be changed. But you can add additional attributes to it, using HttpServletRequest.setAttribute() method. This is useful, when you forward the request to another page:

RequestDispatcher dispatcher = httpServletRequest
    .getRequestDispatcher("/url/to/new/page");
dispatcher.forward(httpServletRequest, httpServletResponse);

The receiving servlet then can read the additional attributes, you set. It has to be in the same web application on the same server instance.

Upvotes: 4

Related Questions