Example usage for javax.servlet.http HttpServletRequest getParameterValues

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

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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.glaf.core.util.HttpQueryUtils.java

public static String getParameter(HttpServletRequest request, String name) {
    String value = request.getParameter(name);
    if (StringUtils.isEmpty(value)) {
        String[] values = request.getParameterValues(name);
        if (values != null && values.length > 0) {
            StringBuffer buff = new StringBuffer(1000);
            for (int i = 0; i < values.length; i++) {
                if (i < values.length - 1) {
                    if (StringUtils.isNotEmpty(values[i])) {
                        buff.append(values[i]).append(',');
                    }//from  ww  w .j  a  v a 2 s  . c  om
                } else {
                    if (StringUtils.isNotEmpty(values[i])) {
                        buff.append(values[i]);
                    }
                }
            }
            if (StringUtils.isNotEmpty(buff.toString())) {
                value = buff.toString();
            }
        }
    }
    return value;
}

From source file:com.attribyte.essem.util.Util.java

/**
 * Gets all parameter values.//from  ww  w .java  2 s  .  c  om
 * @param request The request.
 * @param name The parameter name.
 * @return The values as an immutable list.
 */
public static final ImmutableList<String> getParameterValues(final HttpServletRequest request,
        final String name) {
    String[] vals = request.getParameterValues(name);
    return (vals != null && vals.length > 0) ? ImmutableList.copyOf(vals) : ImmutableList.<String>of();
}

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

/**
 * Request Parameters.//from   w  w  w  .ja v  a  2s .  com
 * 
 * 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: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;//from   w w  w. ja v a2  s. c o m
    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:net.duckling.ddl.web.interceptor.access.FetchCodeInterceptor.java

private static List<Integer> getCurrentRid(HttpServletRequest request) {
    List<Integer> result = new ArrayList<Integer>();
    String r = request.getParameter("rid");
    int rid = 0;//from  w  ww  . ja  v  a  2  s.  c  o m
    if (StringUtils.isEmpty(r)) {
        String path = request.getParameter("path");
        if (!StringUtils.isEmpty(path)) {
            String[] s = path.split("/");
            try {
                rid = Integer.parseInt(s[s.length - 1]);
                result.add(rid);
            } catch (Exception e) {
            }
        } else {
            String[] rids = request.getParameterValues("rids");
            if (rids != null) {
                for (String ri : rids) {
                    try {
                        rid = Integer.parseInt(ri);
                        result.add(rid);
                    } catch (Exception e) {
                    }
                }
            }

        }
    } else {
        rid = Integer.parseInt(r);
        result.add(rid);
    }
    return result;
}

From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java

/**
 * Get a cookie from a request by the cookie name
 * /*from w  ww  .  j av  a2  s.  com*/
 * @param request
 *            the request from which to get the cookie
 * @param cookieName
 *            the name of the cookie to look for
 */
@SuppressWarnings("unchecked")
public static Hashtable<String, String[]> getParameters(HttpServletRequest request) {
    Hashtable<String, String[]> params = new Hashtable<String, String[]>();

    Enumeration<String> paramlist = (Enumeration<String>) request.getParameterNames();
    while (paramlist.hasMoreElements()) {
        String name = (String) paramlist.nextElement();
        String[] value = request.getParameterValues(name);
        params.put(name, value);
    }

    return params;
}

From source file:com.opendesign.utils.ControllerUtil.java

/**
 * Request ? ?  ? Map ? ?.  ?? ? java.util.Array  ?.
 * //  w ww . j a v  a  2 s  . c o  m
 * @param request
 * @return
 */
public static Map<String, Object> createParamMap(HttpServletRequest request) {

    Map<String, Object> paramMap = new HashMap<String, Object>();

    // 2015.09.13 joldo
    // String updateID = SessionManager.getAdminId(request.getSession());
    // String token = request.getParameter("token");
    // paramMap.put("updateID", StringUtils.isEmpty(updateID) ?
    // "${anonymous}" : updateID );
    // paramMap.put("token", StringUtils.isEmpty(token) ? "${anonymous}" :
    // token );

    @SuppressWarnings("rawtypes")
    Enumeration enums = request.getParameterNames();
    while (enums.hasMoreElements()) {

        String paramName = (String) enums.nextElement();
        String[] parameters = request.getParameterValues(paramName);

        // Parameter ? 
        if (parameters.length > 1) {
            for (int i = 0; i < parameters.length; i++) {
                String param = StringUtils.stripToEmpty(parameters[i]);
                parameters[i] = param;
            }
            paramMap.put(paramName, parameters);
            // Parameter ?  
        } else {
            paramMap.put(paramName, StringUtils.stripToEmpty(parameters[0]));
        }
    }

    request.setAttribute("param_map", paramMap);

    return paramMap;
}

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

/**
 * Gets a list of int parameters.// w w w . ja va 2  s .com
 * 
 * @param request
 *            The HttpServletRequest object, known as "request" in a JSP
 *            page.
 * @param name
 *            The name of the parameter you want to get
 * @param defaultNum
 *            The default value of a parameter, if the parameter can't be
 *            converted into an int.
 */
public static int[] getIntParameters(String name, int defaultNum) {
    HttpServletRequest request = getRequest();

    String[] paramValues = request.getParameterValues(name);
    if (paramValues == null) {
        return null;
    }
    if (paramValues.length < 1) {
        return new int[0];
    }
    int[] values = new int[paramValues.length];
    for (int i = 0; i < paramValues.length; i++) {
        try {
            values[i] = Integer.parseInt(paramValues[i].trim());
        } catch (Exception e) {
            values[i] = defaultNum;
        }
    }
    return values;
}

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

/**
 * Gets a list of long parameters./*w  w  w  . j  a v a 2 s  .c om*/
 * 
 * @param request
 *            The HttpServletRequest object, known as "request" in a JSP
 *            page.
 * @param name
 *            The name of the parameter you want to get
 * @param defaultNum
 *            The default value of a parameter, if the parameter can't be
 *            converted into a long.
 */
public static long[] getLongParameters(String name, long defaultNum) {
    HttpServletRequest request = getRequest();

    String[] paramValues = request.getParameterValues(name);
    if (paramValues == null) {
        return null;
    }
    if (paramValues.length < 1) {
        return new long[0];
    }
    long[] values = new long[paramValues.length];
    for (int i = 0; i < paramValues.length; i++) {
        try {
            values[i] = Long.parseLong(paramValues[i].trim());
        } catch (Exception e) {
            values[i] = defaultNum;
        }
    }
    return values;
}

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

/**
 * ???Request Parameters./*from ww  w .j  av  a  2 s .com*/
 * 
 * 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;
}