咱们一般用到request获取某个参数的方法:html
String value=request.getparameter("key");
若是想要获取request中全部的参数呢?数据结构
request中有两种方法能够实现:测试
一、request.getParameterMap();spa
Enumeration enu=request.getParameterNames();
while(enu.hasMoreElements()){
String paraName=(String)enu.nextElement();
System.out.println(paraName+": "+request.getParameter(paraName));
}
二、request.getParameterNames(); htm
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]);
}
} 对象
课外小知识:blog
Enumeration接口
Enumeration接口自己不是一个数据结构。可是,对其余数据结构很是重要。 Enumeration接口定义了从一个数据结构获得连续数据的手段。例如,Enumeration定义了一个名为nextElement的方法,能够用来从含有多个元素的数据结构中获得的下一个元素。
Enumeration接口提供了一套标准的方法,因为Enumeration是一个接口,它的角色局限于为数据结构提供方法协议。下面是一个使用的例子:
//e is an object that implements the Enumeration interface
while (e.hasMoreElements()) {
Object o= e.nextElement();
System.out.println(o);
}
实现该接口的对象由一系列的元素组成,能够连续地调用nextElement()方法来获得 Enumeration枚举对象中的元素。Enumertion接口中仅定义了下面两个方法。
·boolean hasMoreElemerts()
测试Enumeration枚举对象中是否还含有元素,若是返回true,则表示还含有至少一个的元素。
·Object nextElement()
若是Bnumeration枚举对象还含有元素,该方法获得对象中的下一个元素。接口