Example usage for javax.servlet.http HttpServletRequest getParameterNames

List of usage examples for javax.servlet.http HttpServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterNames.

Prototype

public Enumeration<String> getParameterNames();

Source Link

Document

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

Usage

From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java

/**
 * @param request/* w  w w .  j ava2  s  .  c o m*/
 */
public static void printRequestParameters(final HttpServletRequest request) {
    log.debug("Request parameters:");
    final Enumeration<?> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String name = (String) parameterNames.nextElement();
        log.debug(name + " = " + request.getParameter(name));
    }
}

From source file:HttpTransactionUtils.java

/**
 * Set up a simple Map of HTTP request parameters (assumes no duplicate names)
 * /*  ww w.  j a  v a  2 s . c om*/
 * @param request
 *          HttpServletRequest object
 * @return Map of name=value pairs
 */
public static Map getAttributesAsMap(HttpServletRequest request) {
    Enumeration enumeration = request.getParameterNames();
    HashMap map = new HashMap();

    while (enumeration.hasMoreElements()) {
        String name = (String) enumeration.nextElement();

        map.put(name, request.getParameter(name));
    }
    return map;
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 * Request Parameters.//from ww  w  .j  a  va 2  s  .  c  o  m
 * 
 * Parameter.
 */
@SuppressWarnings("unchecked")
public static Map<String, String> getParametersStartingWith(HttpServletRequest request, String prefix) {
    if (prefix == null)
        prefix = "";

    Map params = new TreeMap();
    Enumeration paramNames = request.getParameterNames();

    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0)
                ;// Do nothing, no values found at all.
            else if (values.length > 1)
                params.put(unprefixed, StringUtils.join(values));
            else
                params.put(unprefixed, values[0]);

        }
    }

    return params;
}

From source file:org.openmrs.module.registration.web.controller.util.RegistrationWebUtils.java

/**
 * Optimize the request's parameters//from   ww  w .  j ava 2  s  . c  o  m
 * 
 * @param request
 * @return
 */
public static Map<String, String> optimizeParameters(HttpServletRequest request) {
    Map<String, String> parameters = new HashMap<String, String>();
    for (@SuppressWarnings("rawtypes")
    Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        String parameterName = (String) e.nextElement();
        String[] values = request.getParameterValues(parameterName);
        String value = StringUtils.join(values, ',');
        parameters.put(parameterName, value);
    }
    return parameters;
}

From source file:org.craftercms.core.util.HttpServletUtils.java

public static Map<String, Object> createRequestParamsMap(HttpServletRequest request) {
    Map<String, Object> paramsMap = new HashMap<String, Object>();
    for (Enumeration paramNameEnum = request.getParameterNames(); paramNameEnum.hasMoreElements();) {
        String paramName = (String) paramNameEnum.nextElement();
        String[] paramValues = request.getParameterValues(paramName);

        if (paramValues.length == 1) {
            paramsMap.put(paramName, paramValues[0]);
        } else {/*from  w ww . ja va2  s  . c  o  m*/
            paramsMap.put(paramName, paramValues);
        }
    }

    return paramsMap;
}

From source file:com.bacic5i5j.framework.toolbox.web.WebUtils.java

/**
 * ????map/*from w  w w. j  a v a2s  . c o m*/
 *
 * @param request
 * @return
 */
public static Map convertParameterToMap(HttpServletRequest request) {
    Map params = new HashMap();
    Enumeration enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = WebUtils.getStringParameter(request, paramName, "");
        params.put(paramName, paramValue);
    }

    return params;
}

From source file:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Write request parameters infos into the dump stringbuffer
 * @param sb The dump stringbuffer// ww  w.j a  v  a 2s  .c  o  m
 * @param request The HTTP request
 */
private static void dumpParameters(StringBuffer sb, HttpServletRequest request) {
    String key;
    String[] values;

    Enumeration<String> e = request.getParameterNames();

    while (e.hasMoreElements()) {
        key = e.nextElement();
        values = request.getParameterValues(key);

        int length = values.length;

        for (int i = 0; i < length; i++) {
            dumpVariable(sb, key, values[i]);
        }
    }
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

private static Map<String, String> getRequestMap(HttpServletRequest request, String prefix,
        boolean nameWithPrefix) {
    Map<String, String> map = new HashMap<String, String>();
    Enumeration<String> names = request.getParameterNames();
    String name, key, value;//w  w  w . ja va2 s .  com
    while (names.hasMoreElements()) {
        name = names.nextElement();
        if (name.startsWith(prefix)) {
            key = nameWithPrefix ? name : name.substring(prefix.length());
            value = StringUtils.join(request.getParameterValues(name), ',');
            map.put(key, value);
        }
    }
    return map;
}

From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java

public static String getRequestParam(HttpServletRequest req) {
    String val = "<table>";
    Enumeration names = req.getParameterNames();
    while (names.hasMoreElements()) {

        String name = (String) names.nextElement();
        val += "\n\t<tr><td><h3>" + name + "</h3><td><pre>";
        String value = null;//from w w  w .  j ava  2  s . co  m
        try {
            Object obj = req.getParameter(name);
            value = (obj == null) ? "[null]" : StringEscapeUtils.escapeHtml(obj.toString());
        } catch (Exception ex) {
            value = "unable to get value";
        } catch (Error er) {
            value = "unable to get value";
        } catch (Throwable th) {
            value = "unable to get value";
        }
        val += value + "</pre><td></tr>\n";
    }
    return val + "</table>";
}

From source file:com.lll.util.ServletUtils.java

/**
 * ???Request Parameters.//  w w  w  .  j a va2  s.c  o  m
 * 
 * Parameter???.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map getParametersStartingWith(HttpServletRequest request, String prefix) {
    Enumeration paramNames = request.getParameterNames();
    Map params = new TreeMap();
    if (prefix == null) {
        prefix = "";
    }
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0) {//NOSONAR
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, (Object) values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}