标签:
获取request里的所有参数及参数名(参数名自动获取) - [ Java ] request里有两个方法 request.getParameterMap(); request.getParameterNames(); 我想用这两种方法获取。 1。用request.getParameterNames(); Enumeration enu=request.getParameterNames(); while(enu.hasMoreElements()){ String paraName=(String)enu.nextElement(); System.out.println(paraName+": "+request.getParameter(paraName)); } 2。request.getParameterMap(); Map map=request.getParameterMap(); Set keSet=map.entrySet(); for(Iterator itr=keSet.iterator();itr.hasNext();){ Map.Entry me=(Map.Entry)itr.next(); Object ok=me.getKey(); Object ov=me.getValue(); String[] value=new String[1]; if(ov instanceof String[]){ value=(String[])ov; }else{ value[0]=ov.toString(); } for(int k=0;k<value.length;k++){ System.out.println(ok+"="+value[k]); } }
HashMap newMap = new HashMap(); for(Iterator iter = map.entrySet().iterator();iter.hasNext();){ Map.Entry element = (Map.Entry)iter.next(); Object strKey = element.getKey(); String[] value=(String[])element.getValue(); String valueStr=""; System.out.print(strKey.toString() +"="); for(int i=0;i <value.length;i++){ System.out.print(value[i]+","); valueStr += value[i] +","; } System.out.println(); newMap.put(strKey,valueStr); }
标签:
原文地址:http://my.oschina.net/ydsakyclguozi/blog/422370