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

ServletRequestUtils

abstract class ServletRequestUtils

Parameter extraction methods, for an approach distinct from data binding, in which parameters of specific types are required.

This approach is very useful for simple submissions, where binding request parameters to a command object would be overkill.

Author
Juergen Hoeller

Author
Keith Donald

Since
2.0

Constructors

<init>

ServletRequestUtils()

Parameter extraction methods, for an approach distinct from data binding, in which parameters of specific types are required.

This approach is very useful for simple submissions, where binding request parameters to a command object would be overkill.

Functions

getBooleanParameter

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).

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).

getBooleanParameters

open static fun getBooleanParameters(request: ServletRequest, name: String): BooleanArray

Get an array of boolean parameters, return an empty array if not found.

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

getDoubleParameter

open static fun getDoubleParameter(request: ServletRequest, name: String): Double

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

open static fun getDoubleParameter(request: ServletRequest, name: String, defaultVal: Double): Double

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.

getDoubleParameters

open static fun getDoubleParameters(request: ServletRequest, name: String): DoubleArray

Get an array of double parameters, return an empty array if not found.

getFloatParameter

open static fun getFloatParameter(request: ServletRequest, name: String): Float

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

open static fun getFloatParameter(request: ServletRequest, name: String, defaultVal: Float): Float

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

getFloatParameters

open static fun getFloatParameters(request: ServletRequest, name: String): FloatArray

Get an array of float parameters, return an empty array if not found.

getIntParameter

open static fun getIntParameter(request: ServletRequest, name: String): Int

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

open static fun getIntParameter(request: ServletRequest, name: String, defaultVal: Int): Int

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.

getIntParameters

open static fun getIntParameters(request: ServletRequest, name: String): IntArray

Get an array of int parameters, return an empty array if not found.

getLongParameter

open static fun getLongParameter(request: ServletRequest, name: String): Long

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

open static fun getLongParameter(request: ServletRequest, name: String, defaultVal: Long): Long

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

getLongParameters

open static fun getLongParameters(request: ServletRequest, name: String): LongArray

Get an array of long parameters, return an empty array if not found.

getRequiredBooleanParameter

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

Get a boolean parameter, throwing an exception if it isn't found or 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).

getRequiredBooleanParameters

open static fun getRequiredBooleanParameters(request: ServletRequest, name: String): BooleanArray

Get an array of boolean parameters, throwing an exception if not found or one 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).

getRequiredDoubleParameter

open static fun getRequiredDoubleParameter(request: ServletRequest, name: String): Double

Get a double parameter, throwing an exception if it isn't found or isn't a number.

getRequiredDoubleParameters

open static fun getRequiredDoubleParameters(request: ServletRequest, name: String): DoubleArray

Get an array of double parameters, throwing an exception if not found or one is not a number.

getRequiredFloatParameter

open static fun getRequiredFloatParameter(request: ServletRequest, name: String): Float

Get a float parameter, throwing an exception if it isn't found or isn't a number.

getRequiredFloatParameters

open static fun getRequiredFloatParameters(request: ServletRequest, name: String): FloatArray

Get an array of float parameters, throwing an exception if not found or one is not a number.

getRequiredIntParameter

open static fun getRequiredIntParameter(request: ServletRequest, name: String): Int

Get an int parameter, throwing an exception if it isn't found or isn't a number.

getRequiredIntParameters

open static fun getRequiredIntParameters(request: ServletRequest, name: String): IntArray

Get an array of int parameters, throwing an exception if not found or one is not a number..

getRequiredLongParameter

open static fun getRequiredLongParameter(request: ServletRequest, name: String): Long

Get a long parameter, throwing an exception if it isn't found or isn't a number.

getRequiredLongParameters

open static fun getRequiredLongParameters(request: ServletRequest, name: String): LongArray

Get an array of long parameters, throwing an exception if not found or one is not a number.

getRequiredStringParameter

open static fun getRequiredStringParameter(request: ServletRequest, name: String): String

Get a String parameter, throwing an exception if it isn't found.

getRequiredStringParameters

open static fun getRequiredStringParameters(request: ServletRequest, name: String): Array<String>

Get an array of String parameters, throwing an exception if not found.

getStringParameter

open static fun getStringParameter(request: ServletRequest, name: String): String

Get a String parameter, or null if not present.

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

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

getStringParameters

open static fun getStringParameters(request: ServletRequest, name: String): Array<String>

Get an array of String parameters, return an empty array if not found.