public interface ServletResponse
A typical servlet will output its response as follows:
response.setContentType("text/html; charset=UTF-8");
PrintWriter pw = response.getWriter();
pw.println("Hello, world");
setContentType
or setLocale
to
set the character encoding.
response.setContentType("text/html; charset=ISO-8859-2");
Modifier and Type | Method and Description |
---|---|
void |
flushBuffer()
Flushes the buffer to the client.
|
int |
getBufferSize()
Returns the size of the output buffer.
|
java.lang.String |
getCharacterEncoding()
Returns the character encoding the response is using for output.
|
java.lang.String |
getContentType()
Returns the content type for the response.
|
java.util.Locale |
getLocale()
Returns the output locale.
|
ServletOutputStream |
getOutputStream()
Returns an output stream for writing to the client.
|
java.io.PrintWriter |
getWriter()
Returns a PrintWriter with the proper character encoding for writing
text data to the client.
|
boolean |
isCommitted()
Returns true if some data has actually been send to the client.
|
void |
reset()
Resets the output stream, clearing headers and the output buffer.
|
void |
resetBuffer()
Resets the output stream, clearing headers and the output buffer.
|
void |
setBufferSize(int size)
Sets the output buffer size to
size . |
void |
setCharacterEncoding(java.lang.String charset)
Sets the character encoding the response is using for output.
|
void |
setContentLength(int len)
Explicitly sets the length of the result value.
|
void |
setContentType(java.lang.String type)
Sets the response content type.
|
void |
setLocale(java.util.Locale locale)
Sets the output locale.
|
void setContentType(java.lang.String type)
getWriter()
so the writer can use the
proper character encoding.
To set the output character encoding to ISO-8859-2, use the
following:
response.setContentType("text/html; charset=ISO-8859-2");
type
- the mime type of the outputjava.lang.String getContentType()
java.lang.String getCharacterEncoding()
void setCharacterEncoding(java.lang.String charset)
void setLocale(java.util.Locale locale)
java.util.Locale getLocale()
ServletOutputStream getOutputStream() throws java.io.IOException
java.io.IOException
java.io.PrintWriter getWriter() throws java.io.IOException
java.io.IOException
void setBufferSize(int size)
size
. The servlet engine
may round the size up.size
- the new output buffer size.int getBufferSize()
void flushBuffer() throws java.io.IOException
java.io.IOException
boolean isCommitted()
void reset()
reset()
after data has been committed is illegal.java.lang.IllegalStateException
- if isCommitted()
is true.void resetBuffer()
reset()
after data has been committed is illegal.java.lang.IllegalStateException
- if isCommitted()
is true.void setContentLength(int len)