|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Sends MIME-encoded data from the servlet to the client. The servlet
engine creates a ServletResponse
object and passes it
as an argument to the servlet's service
method.
To send binary data in a MIME body response, use
the ServletOutputStream
returned by getOutputStream()
.
Likewise, to send text data, use the PrintWriter
object
returned by getWriter()
. If you need to mix binary and text data,
for example, if you are creating a multipart response, use a
ServletOutputStream
to write the multipart headers, and
then use the headers to build your own text bodies.
If you do not specify a character set for the MIME body response
with setContentType(java.lang.String)
, the servlet engine will select one
and modify the content accordingly. Call setContentType
before you call getWriter
or getOutputStream
.
See the Internet RFCs such as RFC 2045 at RFC 2045 for more information on MIME. Protocols such as SMTP and HTTP define profiles of MIME, and those standards are still evolving.
ServletOutputStream
Method Summary | |
java.lang.String |
getCharacterEncoding()
Returns the name of the character set encoding used for the MIME body sent by this response. |
ServletOutputStream |
getOutputStream()
Returns a ServletOutputStream suitable for writing binary
data in the response. |
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that you
can use to send character text to the client. |
void |
setContentLength(int len)
Sets the length of the content the server returns to the client. |
void |
setContentType(java.lang.String type)
Sets the content type of the response the server sends to the client. |
Method Detail |
public java.lang.String getCharacterEncoding()
The character encoding is either the one specified in the content itself or another one the client understands. If no character encoding has been assigned, it is implicitly set to text/plain.
See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) for more information about character encoding and MIME.
String
specifying the
name of the character set encoding, for
example, text/plainpublic ServletOutputStream getOutputStream() throws java.io.IOException
ServletOutputStream
suitable for writing binary
data in the response. The servlet engine does not encode the
binary data.ServletOutputStream
for writing binary datagetWriter
method
for the same responsegetWriter()
public java.io.PrintWriter getWriter() throws java.io.IOException
PrintWriter
object that you
can use to send character text to the client.
The character encoding used is the one specified
in the charset=
property of the
setContentType(java.lang.String)
method, which you must call
before you call this method.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
You cannot use this method if you have already
called getOutputStream()
for this
ServletResponse
object.
PrintWriter
object that
can return text to the clientsetContentType
cannot be
usedgetOutputStream
method has already been called for this
response object; in that case, you can't
use this methodgetOutputStream()
,
setContentType(java.lang.String)
public void setContentLength(int len)
len
- an integer specifying the length of the
content being returned to the client; sets
the Content-Length headerpublic void setContentType(java.lang.String type)
text/html; charset=ISO-8859-4
.
You can only use this method once, and you should call it
before you obtain a PrintWriter
or
ServletOutputStream
object to return a response.
type
- a String
specifying the MIME
type of the contentgetOutputStream()
,
getWriter()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |