获取request里面所有的Parameter所有的请求参数

public static Map<String,Object> showParams(HttpServletRequest request) {  
    Map<String,Object> map = new HashMap<String,Object>();  
    Enumeration paramNames = request.getParameterNames();  
    while (paramNames.hasMoreElements()) {  
        String paramName = (String) paramNames.nextElement();  

        String[] paramValues = request.getParameterValues(paramName);  
        if (paramValues.length >0) {  
            String paramValue = paramValues[0];  
            if (paramValue.length() != 0) {  
                map.put(paramName, paramValue);  
            }  
        }  
    }  

    Set<Map.Entry<String, Object>> set = map.entrySet();  
     
    for (Map.Entry entry : set) {  
        System.out.println(entry.getKey() + ":" + entry.getValue());  
    }  
     
    return map;
}

标签: Java

添加新评论