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:io.wcm.sling.commons.request.RequestParam.java

/**
 * Returns a request parameter array.<br>
 * The method fixes problems with incorrect UTF-8 characters returned by the servlet engine.
 * All character data is converted from ISO-8859-1 to UTF-8.
 * @param request Request.//from w ww  . j a v  a 2 s. c o m
 * @param param Parameter name.
 * @return Parameter value array value or null if it is not set.
 */
public static String[] getMultiple(ServletRequest request, String param) {
    String[] values = request.getParameterValues(param);
    if (values == null) {
        return null;
    }
    // convert encoding to UTF-8 if not form encoding parameter is set
    if (!hasFormEncodingParam(request)) {
        String[] convertedValues = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            if (values[i] != null) {
                convertedValues[i] = convertISO88591toUTF8(values[i]);
            }
        }
        return convertedValues;
    } else {
        return values;
    }
}

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

/**
 * ????ServletRequest?/*from ww  w . ja v a  2s  . c  o m*/
 * 
 * @param request ServletRequest
 * @param name ???
 * 
 * @return List
 */
public static List<String> getParameterValues(ServletRequest request, String name) {
    List<String> list = new ArrayList<String>();

    if (request == null || StringUtils.isEmpty(name)) {
        return list;
    }

    String[] values = request.getParameterValues(name);

    if (ArrayUtils.isNotEmpty(values)) {
        CollectionUtils.addAll(list, values);
    } else {
        String value = request.getParameter(name);
        if (StringUtils.isNotEmpty(value)) {
            values = StringUtils.splitByWholeSeparator(value, ",");
        }
    }

    if (values != null && values.length > 0) {
        CollectionUtils.addAll(list, values);
    }

    return list;

}

From source file:dk.netarkivet.harvester.webinterface.ExtendedFieldValueDefinition.java

public static void processRequest(PageContext context, I18n i18n, ExtendableEntity entity, int type) {
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ArgumentNotValid.checkNotNull(i18n, "I18n i18n");

    ExtendedFieldDAO extdao = ExtendedFieldDBDAO.getInstance();
    Iterator<ExtendedField> it = extdao.getAll(type).iterator();

    ServletRequest request = context.getRequest();

    while (it.hasNext()) {
        String value = "";

        ExtendedField ef = it.next();// ww w.j a v a2 s . c  om
        String parameterName = ef.getJspFieldname();
        switch (ef.getDatatype()) {
        case ExtendedFieldDataTypes.BOOLEAN:
            String[] parb = request.getParameterValues(parameterName);
            if (parb != null && parb.length > 0) {
                value = ExtendedFieldConstants.TRUE;
            } else {
                value = ExtendedFieldConstants.FALSE;
            }
            break;
        case ExtendedFieldDataTypes.SELECT:
            String[] pars = request.getParameterValues(parameterName);
            if (pars != null && pars.length > 0) {
                value = pars[0];
            } else {
                value = "";
            }

            break;
        default:
            value = request.getParameter(parameterName);
            if (ef.isMandatory()) {
                if (value == null || value.length() == 0) {
                    value = ef.getDefaultValue();
                }

                if (value == null || value.length() == 0) {
                    HTMLUtils.forwardWithErrorMessage(context, i18n,
                            "errormsg;extendedfields.field.0.is.empty." + "but.mandatory", ef.getName());
                    throw new ForwardedToErrorPage("Mandatory field " + ef.getName() + " is empty.");
                }
            }

            ExtendedFieldDefaultValue def = new ExtendedFieldDefaultValue(value, ef.getFormattingPattern(),
                    ef.getDatatype());
            if (!def.isValid()) {
                HTMLUtils.forwardWithRawErrorMessage(context, i18n, "errormsg;extendedfields.value.invalid");
                throw new ForwardedToErrorPage("errormsg;extendedfields.value.invalid");
            }
            value = def.getDBValue();
            break;
        }

        entity.updateExtendedFieldValue(ef.getExtendedFieldID(), value);
    }
}

From source file:com.zhumeng.dream.util.servlet.ServletUtils.java

/**
 * ???Request Parameters.// w  w w . ja v  a2s  . 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.soolr.core.web.Servlets.java

/**
 * ?Request Parameters, copy from spring WebUtils.
 * //from   w  w w . j a  v a 2s. c  om
 * Parameter
 */
@SuppressWarnings("rawtypes")
public static Map<String, Object> getParameters(ServletRequest request) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    while ((paramNames != null) && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        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(paramName, values);
        } else {
            params.put(paramName, values[0]);
        }
    }
    return params;
}

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

/**
 * ???Request Parameters.//from   ww  w .  j  a  va 2 s .  c o  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 ww  .  j a va2 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>();
    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 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 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:com.dosport.system.utils.ServletUtils.java

/**
 * ???Request Parameters.//from   w ww  .j a va 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.easyframework.common.utils.web.ServletUtils.java

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