Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Methods in the
HttpServlet
class that handle client requests take two arguments:
- An
HttpServletRequest
object, which encapsulates the data from the client
- An
HttpServletResponse
object, which encapsulates the response to the client
An HttpServletRequest
object provides access to HTTP header
data, such as any cookies found in the request and the HTTP method with
which the request was made. The HttpServletRequest
object
also allows you to obtain the arguments that the client sent as part of the
request.
To access client data:
getParameter
method returns the value of a named
parameter. If your parameter could have more than one value, use
getParameterValues
instead. The
getParameterValues
method returns an array of values for the
named parameter. (The method getParameterNames
provides the
names of the parameters.) getQueryString
method returns a
String
of raw data from the client. You must parse this data
yourself to obtain the parameters and values.getReader
method returns a
BufferedReader
for you to use to read the raw data. getInputStream
method
returns a ServletInputStream
for you to use to read the raw data
Note: Useeither agetParameter[Values]
methodor one of the methods that allow you to parse the data yourself. They can not be used together in a single request.
An HttpServletResponse
object provides two ways of returning
data to the user:
getWriter
method returns a Writer
getOutputStream
method returns a
ServletOutputStream
Use the getWriter
method to return text data to the user, and
the getOutputStream
method for binary data.
Closing the Writer
or ServletOutputStream
after
you send the response allows the server to know when the response is complete.
You must set HTTP header data before you access the
Writer
or OutputStream
. The
HttpServletResponse
class provides methods to access the header
data. For example, the setContentType
method sets the content
type. (This header is often the only one manually set.)
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.