WelcomeTo
WelcomeTo

Reputation: 20581

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)

Upvotes: 6

Views: 4225

Answers (1)

e-zinc
e-zinc

Reputation: 4581

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

}

Upvotes: 9

Related Questions