When using request.getParameterMap() to get the data in the Map today, use
Map map=hrequest.getParameterMap();
Set key = map.keySet();
for(Object aaa: key.toArray()){
parakey = aaa.toString ();
paravalue = (String)map.get(aaa);
requestpath = requestpath+"?"+parakey+"="+paravalue;
}
Cannot be cast to java.lang.String error, I checked the Internet and found out that get(key) returns String[], so use string array conversion to read, see the English interface documentation:
So you can create a tool class and convert it into a normal map:
[java] view plain copy
- /**
- * Get the parameter Map from the request and return a readable Map
- *
- * @param request
- * @return
- */
- @SuppressWarnings("unchecked")
- public static Map getParameterMap(HttpServletRequest request) {
- // parameter Map
- Map properties = request.getParameterMap();
- // return value 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;
- }
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission. http://blog.csdn.net/DADADIE/article/details/52085291