HTTPSERVLETREQUEST INTERFACE
There are two important interfaces included in the servlet API HttpServletRequest and
HttpServletResponse
The interface HttpServletRequest encapsulates the functionality for a request object
that is passed to an HTTP Servlet.
It provides access to an input stream and so allows
the servlet to read data from the client. The interface also provides methods for
HttpServletResponse
The interface HttpServletRequest encapsulates the functionality for a request object
that is passed to an HTTP Servlet.
It provides access to an input stream and so allows
the servlet to read data from the client. The interface also provides methods for
parsing the incoming HTTP FORM data and storing the individual data values - in
particular getParameterNames( ) returns the names of all the FORM’s control/value
pairs (request parameters). These control/value pairs are usually stored in an
Enumeration object - such objects are often used for working with an ordered
collection of objects.
Every call to doGet or doPost for an HTTPServlet receives an object that implements
interface HTTPServletRequest. The web server that executes the servlet creates an
HTTPRequest object and passes this to servlet’s service method, hence this object
contains the request from the client. A variety of methods are provided to enable the
servlet to process the client’s request. Some of these methods are listed below:
particular getParameterNames( ) returns the names of all the FORM’s control/value
pairs (request parameters). These control/value pairs are usually stored in an
Enumeration object - such objects are often used for working with an ordered
collection of objects.
Every call to doGet or doPost for an HTTPServlet receives an object that implements
interface HTTPServletRequest. The web server that executes the servlet creates an
HTTPRequest object and passes this to servlet’s service method, hence this object
contains the request from the client. A variety of methods are provided to enable the
servlet to process the client’s request. Some of these methods are listed below:
a) getCookies Servlet Programming
public Cookie[] getCookies();
It returns an array containing all the cookies present in this request. Cookies can be used to uniquely identify clients to servlet. If there are no cookies in the request, then an empty array is returned.
public Cookie[] getCookies();
It returns an array containing all the cookies present in this request. Cookies can be used to uniquely identify clients to servlet. If there are no cookies in the request, then an empty array is returned.
b) getQueryString
public String getQueryString();
It returns query string present in the request URL if any. A query string is defined as any information following a ? character in the URL. If there is no query string, this method returns null.
c) getSession
public HttpSession getSession();
public HttpSession getSession(boolean create);
public HttpSession getSession(boolean create);
Returns the current valid session associated with this request. If this method is called with no arguments, a session will be created for the request if there is not already a session associated with the request. If this method is called with a Boolean argument, then the session will be created only if the argument is true.
To ensure the session is properly maintained, the servlet developer must call this
method before the response is committed. If the create flag is set to false and no session is associated with this request, then this method will return null.
d) getHeader
public String getHeader(String name);
Returns the value of the requested header. The match between the given name and
the request header is case-insensitive. If the header requested does not exist, this
method returns null.
public String getHeader(String name);
Returns the value of the requested header. The match between the given name and
the request header is case-insensitive. If the header requested does not exist, this
method returns null.
e) getParameter(String Name)
public String getParameter(String name)
Returns the value associated with a parameter sent to the servlet as a part of a GET or
POST request. The name argument represents the parameter name.
No comments:
Post a Comment