/** * The default behavior of this method is to return getParameterValues(String name) * on the wrapped request object. */ public String[] getParameterValues(String name) { return this.request.getParameterValues(name); }
/** * Returns HTTP request parameter as String or String[]. */ public static Object getRequestParameter(final ServletRequest request, final String name) { String[] values = request.getParameterValues(name); if (values == null) { return null; } if (values.length == 1) { return values[0]; } return values; }
/** * Get an array of int parameters, throwing an exception if not found or one is not a number.. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static int[] getRequiredIntParameters(ServletRequest request, String name) throws ServletRequestBindingException { return INT_PARSER.parseInts(name, request.getParameterValues(name)); }
/** * Get an array of float parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static float[] getRequiredFloatParameters(ServletRequest request, String name) throws ServletRequestBindingException { return FLOAT_PARSER.parseFloats(name, request.getParameterValues(name)); }
/** * Get an array of double parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static double[] getRequiredDoubleParameters(ServletRequest request, String name) throws ServletRequestBindingException { return DOUBLE_PARSER.parseDoubles(name, request.getParameterValues(name)); }
/** * Get an array of long parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static long[] getRequiredLongParameters(ServletRequest request, String name) throws ServletRequestBindingException { return LONG_PARSER.parseLongs(name, request.getParameterValues(name)); }
/** * Get an array of String parameters, throwing an exception if not found. * @param request current HTTP request * @param name the name of the parameter * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static String[] getRequiredStringParameters(ServletRequest request, String name) throws ServletRequestBindingException { return STRING_PARSER.validateRequiredStrings(name, request.getParameterValues(name)); }
/** * Get an array of boolean parameters, throwing an exception if not found * or one isn't a boolean. * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true; * treats every other non-empty value as false (i.e. parses leniently). * @param request current HTTP request * @param name the name of the parameter * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static boolean[] getRequiredBooleanParameters(ServletRequest request, String name) throws ServletRequestBindingException { return BOOLEAN_PARSER.parseBooleans(name, request.getParameterValues(name)); }
/** * Get an array of double parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static double[] getRequiredDoubleParameters(ServletRequest request, String name) throws ServletRequestBindingException { return DOUBLE_PARSER.parseDoubles(name, request.getParameterValues(name)); }
/** * Get an array of int parameters, throwing an exception if not found or one is not a number.. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static int[] getRequiredIntParameters(ServletRequest request, String name) throws ServletRequestBindingException { return INT_PARSER.parseInts(name, request.getParameterValues(name)); }
/** * Get an array of long parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static long[] getRequiredLongParameters(ServletRequest request, String name) throws ServletRequestBindingException { return LONG_PARSER.parseLongs(name, request.getParameterValues(name)); }
/** * Get an array of float parameters, throwing an exception if not found or one is not a number. * @param request current HTTP request * @param name the name of the parameter with multiple possible values * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static float[] getRequiredFloatParameters(ServletRequest request, String name) throws ServletRequestBindingException { return FLOAT_PARSER.parseFloats(name, request.getParameterValues(name)); }
/** * Get an array of String parameters, throwing an exception if not found. * @param request current HTTP request * @param name the name of the parameter * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static String[] getRequiredStringParameters(ServletRequest request, String name) throws ServletRequestBindingException { return STRING_PARSER.validateRequiredStrings(name, request.getParameterValues(name)); }
if ("".equals(prefix) || paramName.startsWith(prefix)) { String unprefixed = paramName.substring(prefix.length()); String[] values = request.getParameterValues(paramName); if (values == null || values.length == 0) {
/** * Get an array of boolean parameters, throwing an exception if not found * or one isn't a boolean. * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true; * treats every other non-empty value as false (i.e. parses leniently). * @param request current HTTP request * @param name the name of the parameter * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static boolean[] getRequiredBooleanParameters(ServletRequest request, String name) throws ServletRequestBindingException { return BOOLEAN_PARSER.parseBooleans(name, request.getParameterValues(name)); }
@Test // SPR-15835 public void hiddenHttpMethodFilterFollowedByHttpPutFormContentFilter() throws Exception { this.request.addParameter("_method", "PUT"); this.request.addParameter("hiddenField", "testHidden"); this.filter.doFilter(this.request, this.response, this.filterChain); assertArrayEquals(new String[] {"testHidden"}, this.filterChain.getRequest().getParameterValues("hiddenField")); }
@Test public void getParameterValuesFromFormContent() throws Exception { this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("anotherName"); assertNotSame("Request not wrapped", this.request, this.filterChain.getRequest()); assertArrayEquals(new String[] {"anotherValue"}, values); }
@Test public void getParameterValuesInvalidName() throws Exception { this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("noSuchParameter"); assertNotSame("Request not wrapped", this.request, this.filterChain.getRequest()); assertNull(values); }
@Test public void getParameterValues() throws Exception { this.request.setQueryString("name=value1&name=value2"); this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); this.request.setContent("name=value3&name=value4".getBytes("ISO-8859-1")); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("name"); assertNotSame("Request not wrapped", this.request, filterChain.getRequest()); assertArrayEquals(new String[] {"value1", "value2", "value3", "value4"}, values); }
@Test public void getParameterValuesFromQueryString() throws Exception { this.request.setQueryString("name=value1&name=value2"); this.request.addParameter("name", "value1"); this.request.addParameter("name", "value2"); this.request.setContent("anotherName=anotherValue".getBytes("ISO-8859-1")); this.filter.doFilter(this.request, this.response, this.filterChain); String[] values = this.filterChain.getRequest().getParameterValues("name"); assertNotSame("Request not wrapped", this.request, this.filterChain.getRequest()); assertArrayEquals(new String[] {"value1", "value2"}, values); }