Movatterモバイル変換


[0]ホーム

URL:


         


Interface ServletResponse

All Known Subinterfaces:
HttpServletResponse
All Known Implementing Classes:
ServletResponseWrapper

public interfaceServletResponse

Defines an object to assist a servlet in sending a response to the client. The servlet container creates aServletResponse object and passes it as an argument to the servlet'sservice method.

To send binary data in a MIME body response, use theServletOutputStream returned bygetOutputStream(). To send character data, use thePrintWriter object returned bygetWriter(). To mix binary and text data, for example, to create a multipart response, use aServletOutputStream and manage the character sections manually.

The charset for the MIME body response can be specified withsetContentType(java.lang.String). For example, "text/html; charset=Shift_JIS". The charset can alternately be set usingsetLocale(java.util.Locale). If no charset is specified, ISO-8859-1 will be used. ThesetContentType orsetLocale method must be called beforegetWriter for the charset to affect the construction of the writer.

See the Internet RFCs such as RFC 2045 for more information on MIME. Protocols such as SMTP and HTTP define profiles of MIME, and those standards are still evolving.

See Also:
ServletOutputStream

flushBuffer()
          Forces any content in the buffer to be written to the client.
getBufferSize()
          Returns the actual buffer size used for the response.
getCharacterEncoding()
          Returns the name of the charset used for the MIME body sent in this response.
getLocale()
          Returns the locale assigned to the response.
getOutputStream()
          Returns aServletOutputStream suitable for writing binary data in the response.
getWriter()
          Returns aPrintWriter object that can send character text to the client.
isCommitted()
          Returns a boolean indicating if the response has been committed.
reset()
          Clears any data that exists in the buffer as well as the status code and headers.
resetBuffer()
          Clears the content of the underlying buffer in the response without clearing headers or status code.
setBufferSize(int size)
          Sets the preferred buffer size for the body of the response.
setContentLength(int len)
          Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
setContentType(java.lang.String type)
          Sets the content type of the response being sent to the client.
setLocale(java.util.Locale loc)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
 

getCharacterEncoding

public java.lang.StringgetCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response.

If no charset has been assigned, it is implicitly set toISO-8859-1 (Latin-1).

See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) for more information about character encoding and MIME.

Returns:
aString specifying thename of the charset, forexample,ISO-8859-1

getOutputStream

publicServletOutputStreamgetOutputStream()                                    throws java.io.IOException
Returns aServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.

Calling flush() on the ServletOutputStream commits the response. Either this method orgetWriter() may be called to write the body, not both.

Returns:
aServletOutputStream for writing binary data
Throws:
java.lang.IllegalStateException - if thegetWriter method has been called on this response
java.io.IOException - if an input or output exception occurred
See Also:
getWriter()

getWriter

public java.io.PrintWritergetWriter()                              throws java.io.IOException
Returns aPrintWriter object that can send character text to the client. The character encoding used is the one specified in thecharset= property of thesetContentType(java.lang.String) method, which must be calledbefore calling this method for the charset to take effect.

If necessary, the MIME type of the response is modified to reflect the character encoding used.

Calling flush() on the PrintWriter commits the response.

Either this method orgetOutputStream() may be called to write the body, not both.

Returns:
aPrintWriter object that can return character data to the client
Throws:
java.io.UnsupportedEncodingException - if the charset specified insetContentType cannot beused
java.lang.IllegalStateException - if thegetOutputStream method has already been called for this response object
java.io.IOException - if an input or output exception occurred
See Also:
getOutputStream(),setContentType(java.lang.String)

setContentLength

public voidsetContentLength(int len)
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
Parameters:
len - an integer specifying the length of the content being returned to the client; setsthe Content-Length header

setContentType

public voidsetContentType(java.lang.String type)
Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example,text/html; charset=ISO-8859-4.

If obtaining aPrintWriter, this method should be called first.

Parameters:
type - aString specifying the MIME type of the content
See Also:
getOutputStream(),getWriter()

setBufferSize

public voidsetBufferSize(int size)
Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found usinggetBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written, this method throws anIllegalStateException.

Parameters:
size - the preferred buffer size
Throws:
java.lang.IllegalStateException - if this method is called aftercontent has been written
See Also:
getBufferSize(),flushBuffer(),isCommitted(),reset()

getBufferSize

public intgetBufferSize()
Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.
Returns:
the actual buffer size used
See Also:
setBufferSize(int),flushBuffer(),isCommitted(),reset()

flushBuffer

public voidflushBuffer()                 throws java.io.IOException
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
See Also:
setBufferSize(int),getBufferSize(),isCommitted(),reset()

resetBuffer

public voidresetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws anIllegalStateException.
Since:
2.3
See Also:
setBufferSize(int),getBufferSize(),isCommitted(),reset()

isCommitted

public booleanisCommitted()
Returns a boolean indicating if the response has been committed. A commited response has already had its status code and headers written.
Returns:
a boolean indicating if the response has been committed
See Also:
setBufferSize(int),getBufferSize(),flushBuffer(),reset()

reset

public voidreset()
Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws anIllegalStateException.
Throws:
java.lang.IllegalStateException - if the response has already been committed
See Also:
setBufferSize(int),getBufferSize(),flushBuffer(),isCommitted()

setLocale

public voidsetLocale(java.util.Locale loc)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. This method should be called before a call togetWriter(). By default, the response locale is the default locale for the server.
Parameters:
loc - the locale of the response
See Also:
getLocale()

getLocale

public java.util.LocalegetLocale()
Returns the locale assigned to the response.
See Also:
setLocale(java.util.Locale)

         


[8]ページ先頭

©2009-2025 Movatter.jp