在开发中常常会以表单的方式提交一下我们的参数,比如搜索,提交一些信息等,如何一次性获取表单中的参数,下面说一下我们平时不常用的方法
Map data=request.getParameterMap();
这个方法会一次性将参数装进data这个map里面,结构是Map<String,String[]>,为什么value是字符串数组呢,因为这里避免表单中有相同名字的input标签,这个Map是不能直接通过data.get("key"),去获取值的,我们需要将这个Map 转为一个普通的Map ,
如何将data放进一个普通的Map,上demo
Map m=new HashMap();
Iterator iterator = rm.entrySet().iterator();
//遍历
while (iterator.hasNext())
{
Map.Entry entry = (Map.Entry) iterator.next();
Object name = entry.getKey();
String[] value = (String[]) entry.getValue();
if (value != null)
{
if (value.length == 0)
m.put(name, "");
else if (value.length == 1)
m.put(name, value[0]);
else
m.put(name, value);
}
}