I know that I can use HttpServletRequest.getParameter()
to get the URL parameter values.
Is there an equivalent method with which I can set/replace the value?
I know that I can use HttpServletRequest.getParameter()
to get the URL parameter values.
Is there an equivalent method with which I can set/replace the value?
No. However, why would you want to do that? There may be other ways of accomplishing what you need to do.
I don't think there is. But you can use the setAttribute() method in a similar fashion; you just have to use getAttribute() -- not getParameter() -- to get the value back later.
No, there is not.
You can only change attributes, not parameters.
The only way to achieve something similar would be to wrap the request (with a class that returns something else for getParameter).
Related curiosity: There is a bug in some servlet containers that would let you do request.getParameterValues(name)[0] = "newValue"
, but this can only lead to inconsistencies.
You can make the parametermap a modifiable map by replacing the HttpServletRequest
with a custom HttpServletRequestWrapper
implementation which replaces the parametermap inside a Filter
which is been placed early in the chain.
However, this smells like a workaround. In one of the comments you stated that you wanted to encode the parameters (actually: decode them, because they are already encoded). You're looking in the wrong direction for the solution. For GET
request parameters the encoding needs set in the servletcontainer itself (in case of for example Tomcat, just set URIEncoding
attribute of the HTTP connector). For POST
, you need to set it by ServletRequest#setCharacterEncoding()
. Also see the detailed solutions in this article (read the whole article though to understand the complete picture).