[ACCEPTED]-HttpServletRequest - SetParameter-servlets

Accepted answer
Score: 10

No, there is not.

You can only change attributes, not 6 parameters.

The only way to achieve something 5 similar would be to wrap the request (with 4 a class that returns something else for 3 getParameter).

Related curiosity: There is 2 a bug in some servlet containers that would 1 let you do request.getParameterValues(name)[0] = "newValue", but this can only lead to inconsistencies.

Score: 6

You can make the parametermap a modifiable 15 map by replacing the HttpServletRequest with a custom HttpServletRequestWrapper implementation 14 which replaces the parametermap inside a 13 Filter which is been placed early in the chain.

However, this 12 smells like a workaround. In one of the 11 comments you stated that you wanted to encode 10 the parameters (actually: decode them, because 9 they are already encoded). You're looking in the 8 wrong direction for the solution. For GET request 7 parameters the encoding needs set in the 6 servletcontainer itself (in case of for 5 example Tomcat, just set URIEncoding attribute of the 4 HTTP connector). For POST, you need to set it 3 by ServletRequest#setCharacterEncoding(). Also see the detailed solutions in 2 this article (read the whole article though to understand 1 the complete picture).

Score: 4

I don't think there is. But you can use 3 the setAttribute() method in a similar fashion; you just 2 have to use getAttribute() -- not getParameter() -- to 1 get the value back later.

Score: 3

No. However, why would you want to do that? There 2 may be other ways of accomplishing what 1 you need to do.

Score: 1

Request parameters are submitted to a servlet 5 or JSP from a client via HTTP. They are 4 not set by server-side code so there is 3 no need for any set methods (setParameter()).

Also, it 2 will add security that no one can change 1 request parameters.

More Related questions