Using request.getParameterNames() to get all parameter names.
Using request.getParameterValues(paramName) to get all (multiple) parameter values.
Enumeration paramNames = request.getParameterNames(); //All parameters
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName); //All values
....
}
If the paramValues array has only one entry and contains only one empty string, then the parameter had no values. If the array has more than one entry, then the parameter had multiple values.
Using request.getParameterValues(paramName) to get all (multiple) parameter values.
Enumeration paramNames = request.getParameterNames(); //All parameters
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName); //All values
....
}
If the paramValues array has only one entry and contains only one empty string, then the parameter had no values. If the array has more than one entry, then the parameter had multiple values.
An empty String is returned if the parameter exists but has no value, and null is returned if there was no such parameter which name you asked.
No comments:
Post a Comment