Professional Documents
Culture Documents
Reading Parameter
Reading Parameter
Reading Parameter
DATA
Objectives
Reading individual request parameters
Reading entire set of request parameter
Handling missing and malformed data
Filtering special characters out of request
parameter
Automatically filling in a data object with
request parameter values.
Dealing with incomplete form submission.
Reading single values:
To read a request parameter, you simply
call the getParameter() methods of
HttpServletRequest, supplying case-
sensitive parameter name.
An empty String is returned if parameter
exists but it does not have any value.
Null is returned if there was no such
parameter.
getParameterValues()
If same parameter name might
appear in the form data more than
once, you should call
getParameterValues() instead of
getParameter()
The return value of
getParameterValues is null for non
existent parameter names and is a
none element array when
getParameterNames() and
getParameterMap()
The getParameterNames() returns an empty
Enumeration(not null) .
Enumeration is an interface that merely
guarantees that actual class will have
hasMoreElements and nextElement.
An alternative to getParameterNames is
getParameterMap. This method returns a
Map.
Reading input in multiple character
sets: setCharacterEncoding()
By default request.getParameter
interprets inp1ut using the server’s
current character set. To change the
default use setCharacterEncoding()
method of ServletRequest.
Using default values when
parameters are missing
The value is null
The value is an empty string
The value is not empty string of
wrong format.