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.pushio.datacenter.ctrl.util.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*  w  w  w. j a  va  2  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<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    if ((paramNames != null)) {
        while (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.
 * /*  ww  w  . ja v  a2 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:cn.com.qiqi.order.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*from w ww.  ja va2  s  .  c om*/
 * 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.zhumeng.dream.util.servlet.ServletUtils.java

/**
 * ???Request Parameters./*www .j  a  v a  2  s.  c o  m*/
 * 
 * Parameter???.
 */
@SuppressWarnings("unchecked")
public static List<String> getParametersKeyStartingWith(ServletRequest request, String prefix) {
    Assert.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    List<String> keys = Lists.newArrayList();
    if (prefix == null) {
        prefix = "";
    }
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        String[] values = request.getParameterValues(paramName);
        if (values == null || values.length == 0) {
            continue;
        } else if (values.length == 1) {
            if (StringUtils.isBlank(values[0]))
                continue;
        } else {

        }

        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            keys.add(unprefixed);
        }
    }
    return keys;
}

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

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

From source file:net.turnbig.pandora.web.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * /*from  w ww  . ja  v a2 s. c o  m*/
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();

    String prefix_ = 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:org.itboys.commons.utils.servlet.Servlets.java

/**
 * ???Request Parameters, copy from spring.
 * //  w w  w .java2 s.  c  om
 * Parameter???.
 * 
 * m2
 */
@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 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);
            } 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.  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 {
                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.
 * // www.  j a v a2 s.  c o m
 * 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.redhat.rhn.common.util.ServletUtils.java

/**
 * Creates a encoded URL query string with the parameters from the given request. If the
 * request is a GET, then the returned query string will simply consist of the query
 * string from the request. If the request is a POST, the returned query string will
 * consist of the form variables./*  w  w w.  j a  va2 s .  co  m*/
 *
 * <br/><br/>
 *
 * <strong>Note</strong>: This method does not support multi-value parameters.
 *
 * @param request The request for which the query string will be generated.
 *
 * @return An encoded URL query string with the parameters from the given request.
 */
public static String requestParamsToQueryString(ServletRequest request) {

    StringBuffer queryString = new StringBuffer();

    String paramName = null;
    String paramValue = null;

    Enumeration paramNames = request.getParameterNames();

    while (paramNames.hasMoreElements()) {
        paramName = (String) paramNames.nextElement();
        paramValue = request.getParameter(paramName);

        queryString.append(encode(paramName)).append("=").append(encode(paramValue)).append("&");
    }

    if (endsWith(queryString, '&')) {
        queryString.deleteCharAt(queryString.length() - 1);
    }

    return queryString.toString();
}