Thursday, 7 February 2013

HTTP Protocol Parameters | Java Servlets Tutorial pdf

HTTP Protocol Parameters

Request parameters for the servlet are the strings sent by the client to a servlet container as part of its request. When the request is an HttpServletRequest object, and conditions set out in “When Parameters Are Available” the container populates the parameters from the URI query string and POST-ed data.
The parameters are stored as a set of name-value pairs. Multiple parameter values can exist for any given parameter name. 
The following methods of the ServletRequest interface are available to access parameters:
=> getParameter
=> getParameterNames
=> getParameterValues
=> getParameterMap
The getParameterValues method returns an array of String objects containing all the parameter values associated with a parameter name. The value returned from the getParameter method must be the first value in the array of String objects returned by getParameterValues. The getParameterMap method returns a java.util.Map of the parameter of the request, which contains names as keys and parameter values as map values.
Data from the query string and the post body are aggregated into the request parameter set. Query string data is presented before post body data. 
For example,
if a request is made with a query string of a=hello and a post body of a=goodbye&a=world, the resulting parameter set would be ordered a=(hello, goodbye, world).
Path parameters that are part of a GET request (as defined by HTTP 1.1) are not exposed by these APIs. Theymust be parsed from the String values returned by the getRequestURI method or the getPathInfo method.
When Parameters Are Available
The following are the conditions that must be met before post form data will be populated to the parameter set:
1. The request is an HTTP or HTTPS request.
2. The HTTP method is POST.
3. The content type is application/x-www-form-urlencoded.
4. The servlet has made an initial call of any of the getParameter family of methods on the request object.
If the conditions are not met and the post form data is not included in the parameter set, the post data must still be available to the servlet via the request object’s input stream. If the conditions are met, post form data will no longer be available for reading directly from the request object’s input stream.

No comments: