多语言展示
当前在线:970今日阅读:103今日分享:49

打印显示java中http请求request中所有参数

打印显示java中http请求request中所有参数:迭代器获取
工具/原料

jdk eclipse

方法/步骤
1

通过HttpServletRequest获取请求对象request

2

将request中请求参数打印出

3

代码如下:@SuppressWarnings({ 'rawtypes' })    private void showParams(HttpServletRequest request) {        Map map = new HashMap();                Enumeration paramNames = request.getParameterNames();        while(paramNames.hasMoreElements()) {            String paramName = (String) paramNames.nextElement();            String[] paramValues = request.getParameterValues(paramName);            if (paramValues.length == 1) {                if ( paramValues[0].length() != 0) {                    map.put(paramName,  paramValues[0]);                }            }        }        //打印map所有值        Set> set = map.entrySet();        Logger.info('===========================');        for (Map.Entry entry : set) {            Logger.info(entry.getKey() + ':' + entry.getValue());        }        Logger.info('===========================');    } Logger.info------可以通过sysout打印

推荐信息