zoukankan      html  css  js  c++  java
  • getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

    直接遍历报错:[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);

            }

  • 相关阅读:
    ssm整合之配置applicationContext-service.xml
    ssm整合之配置applicationContext-dao.xml
    ssm整合之mybatis配置文件SqlMapConfig.xml
    ssm整合之导包
    java BigDecimal工具类
    java中json依赖包
    Servlet+Json代码
    xstream+dom4j比较对象
    分析堆栈跟踪元素
    myeclipse搭建activemq 简单聊天
  • 原文地址:https://www.cnblogs.com/herosoft/p/5694166.html
Copyright © 2011-2022 走看看