javax.servlet
Interface ServletResponse

All Known Subinterfaces:
CauchoResponse, HttpServletResponse
All Known Implementing Classes:
ServletResponseWrapper

public interface ServletResponse

ServletReponse control the output to the client.

A typical servlet will output its response as follows:

 response.setContentType("text/html; charset=UTF-8");
 PrintWriter pw = response.getWriter();
 pw.println("Hello, world");
 

Buffering

The servlet engine buffers output before sending it to the client. Buffering adds efficiency and flexibility. Until data is actually committed to the client, the servlet can change headers or reset the entire results.

Character encoding

Use either setContentType or setLocale to set the character encoding.
 response.setContentType("text/html; charset=ISO-8859-2");
 


Method Summary
 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.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 setBufferSize(int size)
          Sets the output buffer size to size.
 void setContentLength(int len)
          Deprecated.  
 void setContentType(java.lang.String type)
          Sets the response content type.
 void setLocale(java.util.Locale locale)
          Sets the output locale.
 

Method Detail

setContentType

public void setContentType(java.lang.String type)
Sets the response content type. The content type includes the character encoding. The content type must be set before calling 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");
 
Parameters:
type - the mime type of the output

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the character encoding the response is using for output.

setLocale

public void setLocale(java.util.Locale locale)
Sets the output locale. The response will set the character encoding based on the locale. For example, setting the "kr" locale will set the character encoding to "EUC_KR".

getLocale

public java.util.Locale getLocale()
Returns the output locale.

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws java.io.IOException
Returns an output stream for writing to the client. You can use the output stream to write binary data.

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Returns a PrintWriter with the proper character encoding for writing text data to the client.

setBufferSize

public void setBufferSize(int size)
Sets the output buffer size to size. The servlet engine may round the size up.
Parameters:
size - the new output buffer size.

getBufferSize

public int getBufferSize()
Returns the size of the output buffer.

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Flushes the buffer to the client.

isCommitted

public boolean isCommitted()
Returns true if some data has actually been send to the client. The data will be sent if the buffer overflows or if it's explicitly flushed.

reset

public void reset()
Resets the output stream, clearing headers and the output buffer. Calling reset() after data has been committed is illegal.
Throws:
java.lang.IllegalStateException - if isCommitted() is true.

setContentLength

public void setContentLength(int len)
Deprecated.  

Resin automatically handles output content length and chunking. This method is ignored.