小弟在学习时发现:
<html>
<head>
<title>show form</title>
</head>
<body>
<h2>
These are submitted by the form:
</h2>
<%
   //得到所有的参数名称
   java.util.Enumeration e=request.getParameterNames();
   //对所有参数进行循环
   while(e.hasMoreElements()) 
   {
      //得到参数名
      String name=(String)e.nextElement();
      //得到这个参数的所有值
      String[] value=request.getParameterValues(name);
      //输出参数名
      out.print("<p>");
      out.print("<h3>"+name+":");
      //对一个参数所有的值进行循环
      for(int i=0;i<value.length;i++) 
      {
         //输出一个参数值
         out.print(value[i]);
         if(i!=value.length-1)
         {out.print(",");}
      }
      out.print("</h3></p>");
   }
%>
</body>
</html>   
这个输出后的顺序跟接收原表单数据的顺序不大一样.我这里的结果跟教程上的输出顺序也不一样.不知道是怎么回事.
大虾指点跟什么有关?
表单是:
<html>
<head>
<title>input something in form</title>
</head>
<body>
<h2>
Input something in form.
</h2>
<form name="fm" action="04_02.jsp" method="post">
<p>input text:
<input type="text" name="username">
</p>
<p>input password:
<input type="password" name="password">
</p>
<p>input textarea:
<textarea name="textarea" rows="5" cols="50">
     Hello,This is a textarea.
</textarea>     
</p>
<p>input file:
<input type="file" name="myfile">
</p>
<p><center>
<input type="submit" value="提交">
</center></p>
</body>
</html>我的输出顺序是:
textarea:
password:
myfile:
username:

解决方案 »

  1.   

    request.getParameterNames..顺序跟应用服务器的实现有关,如用的是hashtable或者hashmap(一般也会这么做),那顺序一般会与输入不同。
    要想得到正确的顺序,最安全的办法是自己解析参数,而不要依靠应用服务器解析
      

  2.   

    谢谢ls的解释.能具体说明一下通过"自己解析参数来得到正确的顺序".我想顺序输出.
    我的服务器是Tomcat5.0
      

  3.   

    QueryString和content部分
    用getQueryString 和getInputStream得到吧
    剩下的就是xxx=xxx&yyy=yyy这些的解析了
    还有urlencode的问题