Reputation: 400
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
Reputation: 5315
The HttpServletRequest
object 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