Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet. How to get parameters if their keys are not unique?

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)

like image 863
WelcomeTo Avatar asked Feb 13 '12 16:02

WelcomeTo


People also ask

How would you retrieve a parameter from the servlet request?

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.

What method can be used to retrieve all the parameter values being sent as part of the request by the client?

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.

Which method must be used to retrieve the number of parameters present in the request?

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 .

What is returned by request GET GET method if a specified parameter wasn't submitted?

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.


1 Answers

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);
....

}

like image 124
e-zinc Avatar answered Oct 14 '22 01:10

e-zinc