/** * Get an int 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 int getIntParameter(ServletRequest request, String name, int defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredIntParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get an Integer 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 Integer value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredIntParameter(request, name); }
/** * Get an int 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 int getIntParameter(ServletRequest request, String name, int defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredIntParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get an Integer 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 Integer value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredIntParameter(request, name); }
assertEquals(ServletRequestUtils.getRequiredIntParameter(request, "param1"), 5); ServletRequestUtils.getRequiredIntParameter(request, "param2"); fail("Should have thrown ServletRequestBindingException"); assertEquals(ServletRequestUtils.getIntParameter(request, "param3", 6), 6); try { ServletRequestUtils.getRequiredIntParameter(request, "param3"); fail("Should have thrown ServletRequestBindingException"); ServletRequestUtils.getRequiredIntParameter(request, "paramEmpty"); fail("Should have thrown ServletRequestBindingException");
assertEquals(ServletRequestUtils.getRequiredIntParameter(request, "param1"), 5L);
/** * Get an int 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 int getRequiredIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { return org.springframework.web.bind.ServletRequestUtils.getRequiredIntParameter(request, name); }
/** * Get an int 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 int getIntParameter(ServletRequest request, String name, int defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredIntParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get an int 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 int getIntParameter(ServletRequest request, String name, int defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredIntParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get an Integer 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 Integer value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredIntParameter(request, name); }
/** * Get an Integer 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 Integer value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredIntParameter(request, name); }