Professional Documents
Culture Documents
Servlet 5
Servlet 5
• For HTTP GET requests, the getQueryString method returns a String of raw data from the
client. You must parse this data yourself to obtain the parameters and values.
– If you expect text data, the getReader method returns a BufferedReader for you to
use to read the raw data.
– If you expect binary data, the getInputStream method returns
a ServletInputStream for you to use to read the raw data
• Note: Use either a getParameter[Values] method or one of the methods that allow you
to parse the data yourself. They can not be used together in a single request.
• HttpServletResponse Objects
• An HttpServletResponse object provides two ways of returning data to
the user:
• 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.
• HTTP Header Data
• 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.)