Example usage for javax.servlet ServletRequest getParameterNames

List of usage examples for javax.servlet ServletRequest getParameterNames

Introduction

In this page you can find the example usage for javax.servlet ServletRequest 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:org.yes.cart.web.support.util.HttpUtil.java

private static void dumpParamsAndAttrs(final ServletRequest req, final StringBuilder stringBuilder) {
    final Enumeration parameterNames = req.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        final String key = (String) parameterNames.nextElement();
        stringBuilder.append(MessageFormat.format("\nParameter {0}={1}", key, req.getParameter(key)));
    }//  w  ww .j  a v a 2  s.  com
    Enumeration attributeNames = req.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        final String key = (String) attributeNames.nextElement();
        stringBuilder.append(MessageFormat.format("\nAttribute {0}={1}", key, req.getAttribute(key)));
    }
}

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

/**
 * ???Request Parameters.//from ww  w.  j  a  v a  2s  .  co m
 * 
 * Parameter???.
 */

@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");

    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:com.gc.core.framework.utils.web.ServletUtils.java

/**
 * ???Request Parameters./*from   w  w w .  j a va  2  s  .  c  o m*/
 * 
 * Parameter???.
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:com.ejushang.steward.common.util.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //  w w  w .j  a va2  s . c  o  m
 * Parameter???.
 */
public static Map<String, String[]> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, String[]> params = new TreeMap<String, String[]>();
    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) {
                params.put(unprefixed, new String[0]);
            } else {
                params.put(unprefixed, values);
            }
        }
    }
    return params;
}

From source file:com.weixin.core.util.ServletUtils.java

/**
 * ???Request Parameters./*from w w w.j a v a 2  s  . com*/
 * 
 * Parameter???.
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    Map<String, Object> param = new HashMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
                param.put(paramName, values);
            } else {
                params.put(unprefixed, values[0]);
                param.put(paramName, values[0]);
            }
        }
    }
    request.setAttribute("param", param);
    return params;
}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ???Request Parameters./*ww  w  . j a  va2 s  .c om*/
 * 
 * Parameter???.
 */
@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:com.easyframework.common.utils.web.ServletUtils.java

/**
 * ???Request Parameters.//from  ww w.  java  2s .  co  m
 * 
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:indi.edrik.utils.ServletUtils.java

/**
 * ???Request Parameters.//  w  ww .  ja  va  2  s  .  c om
 * 
 * Parameter???.
 */

@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:com.personal.tools.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * <p>//from  w w  w.  j ava2 s. co m
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> 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)) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:cn.ligoo.part.util.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //from w ww  .  j  av  a2s.c o  m
 * Parameter???.
 */
@SuppressWarnings("rawtypes")
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    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)) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}