JAVA 中用Enumeration遍历Form 表单代码如下:
- Java code
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=gb2312"); PrintWriter out = response.getWriter(); Enumeration <String> paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()){ out.print(paramNames.nextElement()); }。。。。
------解决方案--------------------
你好,request.getParameterNames();里边的结构是Hashtable,不能将其强制转化为Collection类,而Iterator是集合Collection的迭代器,因此不能用Iterator迭代。应该用枚举迭代器Enumeractor,因此只能用枚举类型来迭代。