getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

2023-06-13,,

直接遍历报错:[Ljava.lang.String;@44739f3f

Map<String, String> tempMap = new HashMap<String, String>();
        Map<String, String[]> reqMap = req.getParameterMap();  
        Set<Entry<String, String[]>> set = reqMap.entrySet();  
        Iterator<Entry<String, String[]>> it = set.iterator();  
        while (it.hasNext()) {  
            Entry<String, String[]> entry = it.next();  
 
            System.out.println("KEY:"+entry.getKey());  
            for (String str : entry.getValue()) {  
                System.out.println(str);  
                tempMap.put(entry.getKey(), str);
            }  
        }

顺便写一下Map的遍历:

Set<Map.Entry<String, String>> itermap = resMap.entrySet();
        for (Map.Entry<String, String> entry : itermap) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + ": " + value);

}

getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:的相关教程结束。

《getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:.doc》

下载本文的Word格式文档,以方便收藏与打印。