In servlet I get POST parameters where keys are not unique. Like this
id = 12, id = 13, id = 14
So I can't use getParameterMap()
to get this parameters (because HashMap contain only unique keys). What is the best way to solve this problem and get values from all non-unique parameters from POST query?
Thanks!
UPD. I cant edit request parameters (I retrieve this parameters from other app)
getParameter() method to get the value of a form parameter. getParameterValues() − Call this method if the parameter appears more than once and returns multiple values, for example checkbox. getParameterNames() − Call this method if you want a complete list of all parameters in the current request.
If there's any chance a parameter could have more than one value, you should use the getParameterValues( ) method instead. This method returns all the values of the named parameter as an array of String objects or null if the parameter was not specified.
getParameterNames. Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration .
This method returns the value of the named parameter as a String or null if the parameter was not given. The value is guaranteed to be in its normal, decoded form. If the parameter has multiple values, only the last one is returned.
The method getParameterValues() is especially usefull when there are multiple parameters with the same name in a request. The getParameterValues() method returns the value or values of the parameter paramName. The values are returned in the form of an array of strings. If the parameter paramName has mulitple values in the request, then each of those values is returned in the array.
public abstract interface ServletRequest
{
public abstract String[] getParameterValues(String paramString);
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With