Servlet Post parameters : what case can a parameter have several values?
Here is the a function on my servlet to test various things (I'm new to servlets althought I understadn the logic)
public void testParameters(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
Enumeration paramN开发者_运维问答ames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.println("\n>>>" + paramName);
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0){
out.print("No Value");
}else{
out.print(paramValue);
}
} else {
System.out.println("Number of parameters "+paramValues.length);
for(int i=0; i<paramValues.length; i++) {
out.print("" + paramValues[i]);
}
}
}
}
(this code I took from a tutorial and tweeked so it might just be something stupid)
I get everything working just fine but I was wandering in what cases does a parameter have several values?
Example: http://myhost/path?a=b&a=c&a=d
The parameter a has values b, c and d.
Example:
<form name="checkform" method="post" action="xxxxx">
Which langauge do you want to learn:<br>
<input type="checkbox" name="langtype" value="JSP">JSP
<input type="checkbox" name="langtype" value="PHP">PHP
<input type="checkbox" name="langtype" value="PERL">PERL
<input type="submit" name="b1" value="submit">
</form>
The form can allow you to select multiple values. If you ticks all check boxes , then the parameter langtype will have the values JSP , PHP and PERL
精彩评论