Servlet Post参数:参数有多个值可以是什么情况?

时间:2011-01-26 05:45:33

标签: java post servlets

这是我的servlet上的一个函数,用于测试各种事物(我是servlets的新手,但我还没有理解逻辑)

public void testParameters(HttpServletRequest request,HttpServletResponse response)抛出IOException {   PrintWriter out = response.getWriter();   枚举paramNames = 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(“无价值”);     }其他{      的out.print(paramValue);     }    } else {     System.out.println(“参数个数”+ paramValues.length);     for(int i = 0; i

(这段代码我从一个教程中获取并且已经调整过,所以它可能只是一些愚蠢的事情)

我让一切工作都很好但是我在什么情况下徘徊参数有几个值?

2 个答案:

答案 0 :(得分:2)

示例:http://myhost/path?a=b&a=c&a=d
参数a具有值b,c和d。

答案 1 :(得分:2)

示例:

<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>

表单可以让您选择多个值。如果勾选所有复选框,则参数langtype将具有值JSP,PHP和PERL