The Request
We’ve seen how the servlet finds out about the server and about the client. Now it’s time to move on to the really important stuff: how a servlet finds out what the client wants.
Request Parameters
Each access to a servlet can have any number of request parameters associated with it. These parameters are typically name/value pairs that tell the servlet any extra information it needs to handle the request. Please don’t confuse these request parameters with init parameters, which are associated with the servlet itself.
An HTTP servlet gets its request parameters as part of its query
string (for GET requests) or as encoded post data (for POST
requests). A servlet used as a server-side include has its parameters
supplied by PARAM tags. Other types of
servlets can receive their parameters in other ways.
Fortunately, even though a servlet can receive parameters in a number
of different ways, every servlet retrieves its parameters the same
way, using getParameter()
and getParameterValues()
:
public String ServletRequest.getParameter(String name) public String[] ServletRequest.getParameterValues(String name)
getParameter() returns the value of the named
parameter as a String or null
if the parameter was not specified.[22] The value is guaranteed to be in its
normal, decoded form. If the parameter has multiple values, the value
returned is server-dependent. If there’s any chance a parameter
could have more than one value, you should use the
getParameterValues() method instead. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access