I want to add a new parameter to the parameter map of my HttpServletRequest
.
The following code
request().getParameterMap().put(\"j_use
I ran into a similar issue and got around it by making a copy of the parameter map.
Map<String, String[]> params = new HashMap<String, String[]>(req.getParameterMap());
The parameters of a request are the values sent as parameters by the browser. There is no reason to change them. If you want to associate some value to the request, use an attribute rather than a parameter. This has the additional advantage that an attribute may be any object and not just a String:
request.setAttribute("user", new User(userName, password));
You may add parameters if you forward the request to another resource (although I wouldn't say it's a good practice):
request.getRequestDispatcher("/some/path?j_username=" + user + "&j_password=" + pwd).forward(request, response);
The parameters should be encoded correctly, though.