Example usage for javax.servlet ServletRequest getParameterValues

List of usage examples for javax.servlet ServletRequest getParameterValues

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:com.github.dactiv.common.utils.ServletUtils.java

/**
 * ???Request Parameters.//from   ww w .j a  v a 2  s  .  c  o 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) {

            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:cn.com.qiqi.order.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //from  w ww  .j a  v a2 s . co 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;
}

From source file:com.eastteam.myprogram.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /* w  w w  .  ja va2  s .  c o 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<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 if (StringUtils.isNotBlank(values[0])) {
                params.put(unprefixed, values[0].trim());
            }
            if (unprefixed.startsWith("categoryId") && values != null) {
                params.put("categoryIdList", values);
            }
        }
    }
    return params;
}

From source file:com.sobey.framework.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*from   www .ja  va 2 s  . co 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;
}

From source file:com.mxep.web.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * <p>/*from   w ww.  j av  a  2 s.com*/
 * 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<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]);
            }
        }
        //           else {
        //                params.put(paramName, request.getParameter(paramName));
        //            }
    }
    return params;
}

From source file:com.gmail.sretof.web.ServletUtils.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*from  ww w  . j  a  v  a 2s  . com*/
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    @SuppressWarnings("rawtypes")
    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.shz.foundation.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //from   ww  w.j  a v  a 2 s  . c o m
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration<String> paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    while ((paramNames != null) && paramNames.hasMoreElements()) {
        String paramName = 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.weixin.core.util.ServletUtils.java

/**
 * ???Request Parameters./*  w  ww.j av a  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>();
    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.emaxcore.emaxdata.common.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 *
 * Parameter???./*from  ww w  . j  a va  2s. c o  m*/
 */
@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 pre = prefix;
    if (pre == null) {
        pre = "";
    }
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(pre) || paramName.startsWith(pre)) {
            String unprefixed = paramName.substring(pre.length());
            String[] values = request.getParameterValues(paramName);
            if (values != null && values.length > 1) {
                params.put(unprefixed, values);
            } else {
                if (values != null && values.length == 1) {
                    params.put(unprefixed, values[0]);
                }
            }
        }
    }
    return params;
}

From source file:com.androidwhy.modules.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * // w  w  w  .  j  a  va  2s .  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<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());
            unprefixed = unprefixed.replace("__", ".");
            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;
}