Although the parameter map can be easily obtained by Request.getparametermap () in a Java Web project, the resulting map is not the same as the normal map, it is locked, and cannot be put, get, and so on as the normal map. This method will get the parameter map back as an operational normal map
Tags:Java Request Getparametermap Anynote Code Snippet (1) [Full screen view of all code]1. Code [Java] Code?
| 1234567891011121314151617181920212223242526272829303132333435 |
/** * 从request中获得参数Map,并返回可读的Map * * @param request * @return */@SuppressWarnings("unchecked")public static Map getParameterMap(HttpServletRequest request) { // 参数Map Map properties = request.getParameterMap(); // 返回值Map Map returnMap = new HashMap(); Iterator entries = properties.entrySet().iterator(); Map.Entry entry; String name = ""; String value = ""; while (entries.hasNext()) { entry = (Map.Entry) entries.next(); name = (String) entry.getKey(); Object valueObj = entry.getValue(); if(null == valueObj){ value = ""; }else if(valueObj instanceof String[]){ String[] values = (String[])valueObj; for(int i=0;i<values.length;i++){ value = values[i] + ","; } value = value.substring(0, value.length()-1); }else{ value = valueObj.toString(); } returnMap.put(name, value); } return returnMap;} |
Convert Request.getparametermap () to an operational normal map