List of usage examples for javax.servlet ServletRequest getParameterValues
public String[] getParameterValues(String name);
String
objects containing all of the values the given request parameter has, or null
if the parameter does not exist. From source file:com.github.tx.archetype.common.util.Servlets.java
/** * ???Request ParametersParameter???//from w w w .j a va2 s. c o m * @param request * @param prefix ? * @param ignoreEmptyValue ? * @return */ public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix, boolean ignoreEmptyValue) { Validate.notNull(request, "Request must not be null"); Enumeration paramNames = request.getParameterNames(); Map<String, Object> params = Maps.newHashMap(); 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) { for (int i = 0; i < values.length; i++) { values[i] = values[i].trim(); } } if ((values == null) || (values.length == 0)) { // Do nothing, no values found at all. } else if (values.length > 1) { params.put(unprefixed, values); } else { if (!ignoreEmptyValue) { params.put(unprefixed, values[0]); } else { if (StringUtils.isNotBlank(values[0])) { params.put(unprefixed, values[0]); } } } } } return params; }
From source file:com.innovate.cms.common.web.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * // www. j av a 2s . com * 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>(); 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 == 0) { values = new String[] {}; // 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.cnksi.core.web.utils.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * //from w ww . j av a2 s .com * Parameter???. * * @param dwzExport true|false ?ExcelValue??? */ public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix, boolean dwzExport) { 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]); } } } if (dwzExport) { Iterator<String> it = params.keySet().iterator(); while (it.hasNext()) { try { String key = it.next(); String value = params.get(key).toString(); String encodedValue = new String(value.getBytes("ISO8859-1"), "UTF-8"); params.put(key, encodedValue); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return params; }
From source file:com.age.core.utils.web.ServletUtils.java
/** * ???Request Parameters./*from ww w . ja va 2s . c o m*/ * * Parameter???. */ public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { AssertUtils.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.soolr.core.web.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * /* ww w. j a v 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>(); 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:com.soolr.core.web.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * // www.jav a 2s . com * Parameter???. */ public static Map<String, Object> getPmParametersStartingWith(ServletRequest request, String prefix) { Validate.notNull(request, "Request must not be null"); 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]); } } else {//?? 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.sunway.cbm.util.ServletUtils.java
/** * ???Request Parameters.//from w ww .j av a2 s . c om * * Parameter???. */ public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { AssertUtils.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:org.jruby.rack.mock.WebUtils.java
/** * Return a map containing all parameters with the given prefix. * Maps single values to String and multiple values to String array. * <p>For example, with a prefix of "spring_", "spring_param1" and * "spring_param2" result in a Map with "param1" and "param2" as keys. * @param request HTTP request in which to look for parameters * @param prefix the beginning of parameter names * (if this is null or the empty string, all parameters will match) * @return map containing request parameters <b>without the prefix</b>, * containing either a String or a String array as values * @see javax.servlet.ServletRequest#getParameterNames * @see javax.servlet.ServletRequest#getParameterValues * @see javax.servlet.ServletRequest#getParameterMap *///www.j av a 2 s . co m public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { Assert.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.doculibre.constellio.filters.SetCharacterEncodingFilter.java
/** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * /* w w w. jav a 2s .co m*/ * @param request * The servlet request we are processing * @param result * The servlet response we are creating * @param chain * The filter chain we are processing * @exception IOException * if an input/output error occurs * @exception ServletException * if a servlet error occurs */ @SuppressWarnings("unchecked") public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (false) { chain.doFilter(request, response); } else { String lookupCharSet = lookupCharSet(request); SimpleParams simpleParams = new SimpleParams(); Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); String convertedParamName = convertIfNeeded(paramName, lookupCharSet); String[] paramValues = request.getParameterValues(paramName); List<String> convertedParamValues = new ArrayList<String>(); if (paramValues != null) { for (String paramValue : paramValues) { String convertedParamValue = convertIfNeeded(paramValue, lookupCharSet); if (convertedParamValue != null) { convertedParamValues.add(convertedParamValue); } } } simpleParams.add(convertedParamName, convertedParamValues.toArray(new String[0])); } HttpServletRequest requestWrapper = new SimpleParamsHttpServletRequestWrapper( (HttpServletRequest) request, simpleParams); // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String encoding = selectEncoding(request); if (encoding != null) { request.setCharacterEncoding(encoding); } } // Pass control on to the next filter chain.doFilter(requestWrapper, response); } }
From source file:com.xsw.utils.Servlets.java
/** * ???Request Parameters, copy from spring WebUtils. * /*from w w w .j a v a 2 s.c om*/ * Parameter???. */ public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) { Validate.notNull(request, "Request must not be null"); Map<String, Object> params = new TreeMap<String, Object>(); if (prefix == null) { prefix = ""; } // process Attribute Enumeration<String> paramNames = request.getAttributeNames(); while (paramNames != null && paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); if ("".equals(prefix) || paramName.startsWith(prefix)) { String unprefixed = paramName.substring(prefix.length()); Object attobj = request.getAttribute(paramName); String[] values = null; if (attobj instanceof String[]) { values = (String[]) attobj; } else { values = new String[1]; values[0] = String.valueOf(attobj); } 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]); } } } // process parameter paramNames = request.getParameterNames(); 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; }