zoukankan      html  css  js  c++  java
  • JavaEE中request.getParameterMap()转普通Map

    在java web项目中虽然可以通过request.getParameterMap()很轻松的获得参数Map,但得到的Map和普通Map是不一样的,是被锁定的,不能像操作常规Map那样进行put、get等操作,该方法将得到参数Map返回为可操作的普通Map
     1 /**
     2  * 从request中获得参数Map,并返回可读的Map
     3  * 
     4  * @param request
     5  * @return
     6  */
     7 @SuppressWarnings("unchecked")
     8 public static Map getParameterMap(HttpServletRequest request) {
     9     // 参数Map
    10     Map properties = request.getParameterMap();
    11     // 返回值Map
    12     Map returnMap = new HashMap();
    13     Iterator entries = properties.entrySet().iterator();
    14     Map.Entry entry;
    15     String name = "";
    16     String value = "";
    17     while (entries.hasNext()) {
    18         entry = (Map.Entry) entries.next();
    19         name = (String) entry.getKey();
    20         Object valueObj = entry.getValue();
    21         if(null == valueObj){
    22             value = "";
    23         }else if(valueObj instanceof String[]){
    24             String[] values = (String[])valueObj;
    25             for(int i=0;i<values.length;i++){
    26                 value = values[i] + ",";
    27             }
    28             value = value.substring(0, value.length()-1);
    29         }else{
    30             value = valueObj.toString();
    31         }
    32         returnMap.put(name, value);
    33     }
    34     return returnMap;
    35 }
  • 相关阅读:
    HDU 1850 Being a Good Boy in Spring Festival
    UESTC 1080 空心矩阵
    HDU 2491 Priest John's Busiest Day
    UVALive 6181
    ZOJ 2674 Strange Limit
    UVA 12532 Interval Product
    UESTC 1237 质因子分解
    UESTC 1014 Shot
    xe5 android listbox的 TMetropolisUIListBoxItem
    xe5 android tts(Text To Speech)
  • 原文地址:https://www.cnblogs.com/chenhao1990/p/4628946.html
Copyright © 2011-2022 走看看