Handling The Client Request: Form Data Objectives

You might also like

Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 8

 Handling The Client Request:

FORM DATA
 Objectives
 Reading individual request
parameters
 Reading entire set of request
parameter
 Handling missing and malformed data
 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.
 getReader() or getInputStrem() :
instead of reading individual form
parameters you can access query
data directly by using getReader()
or getInputStream() methods.

You might also like