Important HttpServlet Supporting Classes
About HttpServletRequest and HttpServletResponse
HttpServletRequest
- Represents the client request
- Use getParameter("name") to get the
value of parameter "name" sent in the HTTP request.
- Use getParameterValues("name") if
you think there may be more than one value associated with the
parameter "name" sent in the HTTP request. Will return an
array of Strings (this array will be null, or have a length or
1 if there are no or only values for this parameter respectively).
- Use getParameterNames() to return
(as an Enumeration object) the entire set of names of parameters
passed via the HTTP request.
- Use getHeader("headerName")
to revtrieve the value of the HTTP Request Header type "headerName".
About HTTP Request Header
types.
- Use getHeaderNames() to return (as an Enumeration object)
the entire set of names of headers passed via the HTTP request.
- Use getMethod() to return the request method used (GET,
POST, etc.)
- Use getRequestURI to return the part of the URL that comes
after host and port but, before the form data.
- Use getProtocol to return returns the third part of the
request line which is generally HTTP/1.0 or HTTP/1.1 ,etc.
- Has other rich set of methods...see
API. Example getCookies(), returns an array of any Cookies
sent to it in the HTTP Request Header.
|
HttpServletResponse
- About HTTP Response Header
- Use to return response to client.
- Can use methods like getWriter() to
retrieve Writer for output to the client.
- Before sending the created data/document
you should do is call method setContentType() to tell the client
what kind (e.g. "text/html"), MIME type, of data/document you
will be returning.
- response.setContentType("text/html");
|
ServletUtilities
This is a Class created by
Author of our "Core Servlets and JSP" book. See book and corresponding
web-site for details and source code you will need to copy and compile!!!!
- Utility class, number of useful static
methods.
- headWithTitle(String) = static method
that takes a string representing a title to an HTML document and
constructs using it, the appropriate header HTML tags, returns
this as a String.
- getCookieValue(cookie_array, "name",
"default_value") = static method that loops through the array
of Cookies, looking for one who's name matches "name" and
will return its value if it exists....if it does not find the
cookie, it will return the "default_value" String you specified.
- getCookie(cookie_array, "name"); =
static method that loops through the array of Cookies, looking
for one who's name matches "name" and it will return this cookie
if it exists.
|
|