/** * Get an array of double parameters, return an empty array if not found. * @param request current HTTP request * @param name the name of the parameter with multiple possible values */ public static double[] getDoubleParameters(ServletRequest request, String name) { try { return getRequiredDoubleParameters(request, name); } catch (ServletRequestBindingException ex) { return new double[0]; } }
/** * Get an array of double parameters, return an empty array if not found. * @param request current HTTP request * @param name the name of the parameter with multiple possible values */ public static double[] getDoubleParameters(ServletRequest request, String name) { try { return getRequiredDoubleParameters(request, name); } catch (ServletRequestBindingException ex) { return new double[0]; } }
@Test public void testDoubleParameters() throws ServletRequestBindingException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("param", new String[] {"1.5", "2.5", "3"}); request.addParameter("param2", "1.5"); request.addParameter("param2", "2"); request.addParameter("param2", "bogus"); double[] array = new double[] {1.5, 2.5, 3}; double[] values = ServletRequestUtils.getRequiredDoubleParameters(request, "param"); assertEquals(3, values.length); for (int i = 0; i < array.length; i++) { assertEquals(array[i], values[i], 0); } try { ServletRequestUtils.getRequiredDoubleParameters(request, "param2"); fail("Should have thrown ServletRequestBindingException"); } catch (ServletRequestBindingException ex) { // expected } }
/** * 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 org.springframework.web.bind.ServletRequestUtils.getRequiredDoubleParameters(request, name); }
/** * Get an array of double parameters, return an empty array if not found. * @param request current HTTP request * @param name the name of the parameter with multiple possible values */ public static double[] getDoubleParameters(ServletRequest request, String name) { try { return getRequiredDoubleParameters(request, name); } catch (ServletRequestBindingException ex) { return new double[0]; } }
/** * Get an array of double parameters, return an empty array if not found. * @param request current HTTP request * @param name the name of the parameter with multiple possible values */ public static double[] getDoubleParameters(ServletRequest request, String name) { try { return getRequiredDoubleParameters(request, name); } catch (ServletRequestBindingException ex) { return new double[0]; } }