/** * Get a double parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static double getDoubleParameter(ServletRequest request, String name, double defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredDoubleParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Double parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Double value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredDoubleParameter(request, name); }
/** * Get a double parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static double getDoubleParameter(ServletRequest request, String name, double defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredDoubleParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Double parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Double value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredDoubleParameter(request, name); }
assertTrue(ServletRequestUtils.getRequiredDoubleParameter(request, "param1") == 5.5); ServletRequestUtils.getRequiredDoubleParameter(request, "param2"); fail("Should have thrown ServletRequestBindingException"); assertTrue(ServletRequestUtils.getDoubleParameter(request, "param3", 6.5) == 6.5); try { ServletRequestUtils.getRequiredDoubleParameter(request, "param3"); fail("Should have thrown ServletRequestBindingException"); ServletRequestUtils.getRequiredDoubleParameter(request, "paramEmpty"); fail("Should have thrown ServletRequestBindingException");
/** * Get a double parameter, throwing an exception if it isn't found or isn't a number. * @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 double getRequiredDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { return org.springframework.web.bind.ServletRequestUtils.getRequiredDoubleParameter(request, name); }
/** * Get a double parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static double getDoubleParameter(ServletRequest request, String name, double defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredDoubleParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a double parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static double getDoubleParameter(ServletRequest request, String name, double defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredDoubleParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Double parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Double value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredDoubleParameter(request, name); }
/** * Get a Double parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Double value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredDoubleParameter(request, name); }