spring-framework / org.springframework.web.bind / ServletRequestUtils / getBooleanParameter

getBooleanParameter

@Nullable open static fun getBooleanParameter(request: ServletRequest, name: String): Boolean

Get a Boolean parameter, or null if not present. Throws an exception if it the parameter value isn't a boolean.

Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).

Parameters

request - current HTTP request

name - the name of the parameter

Exceptions

ServletRequestBindingException - a subclass of ServletException, so it doesn't need to be caught

Return
the Boolean value, or null if not present

open static fun getBooleanParameter(request: ServletRequest, name: String, defaultVal: Boolean): Boolean

Get a boolean parameter, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Accepts "true", "on", "yes" (any case) and "1" as values for true; treats every other non-empty value as false (i.e. parses leniently).

Parameters

request - current HTTP request

name - the name of the parameter

defaultVal - the default value to use as fallback