首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

java将请求参数封转成地图

2013-11-09 
java将请求参数封转成mappackage com.cz.utilimport java.util.HashMapimport java.util.Iteratorimpor

java将请求参数封转成map
package com.cz.util;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.servlet.http.HttpServletRequest;public class Common { /** * 从request中获得参数Map,并返回可读的Map * * @param request * @return */@SuppressWarnings("unchecked")public static Map getParameterMap(HttpServletRequest request) {// 参数MapMap properties = request.getParameterMap();// 返回值MapMap 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;}}

?

热点排行