All Packages Class Hierarchy This Package Previous Next Index
Class WebSite.Servlet.Response
java.lang.Object
|
+----WebSite.Servlet.Response
- public final class Response
- extends Object
The Response class implements the WebSite Servlet response
information and methods. It is a purely static class and cannot be
instantiated.
The standard line terminator for HTTP (and other Internet
protocols) is CR-LF. The println methods here generate these
line endings. This class implements most of the methods of
the PrintStream class, but with proper line terminators and
better error detection.
The output is normally spooled. This is the preferred mode of operation,
as described in the documentation for Client.unspool(), which
may be called to defeat the spooling. Unspooling the output is useful
when you need a "hot" connection to the browser for things like
server-push.
When running in spooled mode, output is normally eligible to be
sent through WebSite's
post-processing chain. This means that servlet output may contain
things like server-side include tags. You must set the content-type to
that which is handled by the post-processor you want to handle your
output. For example, to have your servlet output run through the
server-side include engine, set your content type to
wwwserver/html-ssi. You may defeat this feature (and
realize a small performance gain) by calling
Response.usePostProc(false).
Response cookie support provides the functionality described in the
Netscape Cookie Specification and the new
RFC
2109 State Management cookies.
- See Also:
- Client, Cookie, Form, Request, Server, Session
-
addExtraHeader(String, String)
- Adds an extra meta-information header to the response.
-
containsExtraHeader(String)
- Returns true if the response contains the named
extra header.
-
endErrorResponse()
- Finish off an HTTP "500 Server Error" response that was started
with startErrorResponse.
-
extraHeaderCount()
- Returns the number of extra headers in the response.
-
extraHeaderNames()
- Returns an Enumeration of the extra header names in the response.
-
getCookies()
- Returns a Vector of Cookie objects representing the cookies
that have been set in the response.
-
getExtraHeader(String)
- Gets the value of the named response extra header, or null if it
is not present.
-
noOp()
- Sends a "no-op" (204) to the client.
-
print(boolean)
- Prints a boolean.
-
print(char)
- Prints a character.
-
print(char[])
- Prints an array of characters.
-
print(double)
- Prints a double.
-
print(float)
- Prints a float.
-
print(int)
- Prints an integer.
-
print(long)
- Prints a long.
-
print(Object)
- Prints an object.
-
print(String)
- Prints a string
-
print(StringBuffer)
- Prints a string buffer.
-
println()
- Prints a line terminator
-
println(boolean)
- Prints a boolean followed by a line terminator.
-
println(char)
- Prints a character followed by a line terminator.
-
println(char[])
- Prints an array of characters followed by a line terminator.
-
println(double)
- Prints a double followed by a line terminator.
-
println(float)
- Prints a float followed by a line terminator.
-
println(int)
- Prints an integer followed by a line terminator.
-
println(long)
- Prints a long followed by a line terminator.
-
println(Object)
- Prints an object followed by a line terminator.
-
println(String)
- Prints a string followed by a line terminator.
-
println(StringBuffer)
- Prints a string buffer followed by a line terminator.
-
redirect(String)
- Sends a redirection response (302) to the client, causing it to
immediately fetch the target URL.
-
sendHeaders()
- Immediately sends the HTTP headers to the client.
-
setContentType(String)
- Sets the media content type for the response body.
-
setCookie(Cookie)
- Sets a response cookie using a given Cookie object.
-
setCookie(String, String)
- Sets a response cookie with default attributes and the
given name and string
value.
-
setStatus(String)
- Sets the HTTP status code and reason phrase for the response.
-
startErrorResponse()
- Start an HTTP "500 server error" response.
-
unspool()
- Unspool (unbuffer) the output.
-
usePostProc(boolean)
- Enable or disable server post-processing on servlet output.
-
write(byte[])
- Writes an array of bytes
-
write(byte[], int, int)
- Writes a sub-array of bytes
-
write(int)
- Writes a byte of data
usePostProc
public static native void usePostProc(boolean enabled) throws IOException
- Enable or disable server post-processing on servlet output. Default is
to pass the servlet output through any configured post-processor(s).
If you disable it, you cannot use WebSite Pro features such as server-side
includes and the automatic S-HTTP anchor fixup. If you are certain you
will not need these services for your servlet output, you can disable
post-processing to eliminate the extra CPU and disk utilization needed
to set up for post-processing. Post-processing is disabled if you
unspool the output.
- Parameters:
- enabled - true to enable post-processing, false
to disable it.
- Throws: IOException
- Thrown if you attempt to change this setting
after using any of the methods that send content to the client, or
after unspooling the output.
- See Also:
- unspool
unspool
public static native void unspool() throws IOException
- Unspool (unbuffer) the output. This causes response data
to go directly to the TCP
socket in whatever sized bits you write. All HTTP headers are
automatically transmitted on the first write to the output. Post
processors are disabled. You must unbuffer the output before
writing anything. You are responsible for setting a correct
content length a priori, before writing anything. If you
do not know how much data you will be sending, you must disable
keep-alive.
This feature is mainly useful for server-push applications.
Unbuffering will not improve performance in general. The
small execution speed increase is easily offset by the inefficiencies
in transmitting small bits of data over the net to the client.
WebSite's memory-mapped buffering maximizes network packet size
and transmits all response packets as closely spaced in time as
possible. This reduces the probably that packets will take different
routes through the net and thereby suffer reassembly delays.
- Throws: IOException
- Thrown if you attempt to change this setting
after using any of the methods that send content to the client.
setCookie
public static void setCookie(String name,
String value) throws IOException
- Sets a response cookie with default attributes and the
given name and string
value. For complete control over the cookie attributes, use
the form of setCookie() that takes the Cookie object. The
cookie will be compatible with both Netscape or RFC 2109
as it will consist only of the NAME=VALUE pair.
- Parameters:
- name - The name of the cookie
- value - The value of the cookie
- Throws: IOException
- Thrown if you attempt to set a cookie
after using any of the methods that send content to the client.
setCookie
public static void setCookie(Cookie ck) throws IOException
- Sets a response cookie using a given Cookie object.
- Parameters:
- ck - The Cookie object
- Throws: IOException
- Thrown if you attempt to set a cookie
after using any of the methods that send content to the client.
- See Also:
- Cookie
getCookies
public static native Vector getCookies()
- Returns a Vector of Cookie objects representing the cookies
that have been set in the response.
containsExtraHeader
public static boolean containsExtraHeader(String name)
- Returns true if the response contains the named
extra header.
- Parameters:
- name - The name (label) of the extra header
getExtraHeader
public static String getExtraHeader(String name)
- Gets the value of the named response extra header, or null if it
is not present.
- Parameters:
- name - The name (label) of the extra header
extraHeaderCount
public static int extraHeaderCount()
- Returns the number of extra headers in the response.
extraHeaderNames
public static Enumeration extraHeaderNames()
- Returns an Enumeration of the extra header names in the response.
The Enumeration returns String objects that contain the header
name or label of a response extra header. Note that response extra
headers may be present even if you do not set any yourself.
setContentType
public static native void setContentType(String ct) throws IOException
- Sets the media content type for the response body. The default
is
text/html, used for HTML responses. Setting this
to an empty string or null will supress the Content-Type
header in the response. The call to this method must occur
before any content is written/printed.
- Parameters:
- ct - the media content type, for example text/html
- Throws: IOException
- Thrown if you attempt to set the content type
after using any of the methods that send content to the client.
setStatus
public static native void setStatus(String st) throws IOException
- Sets the HTTP status code and reason phrase for the response. The
default is "200 OK". Allows construction of any HTTP response. The call
to this method must occur before any content is written/printed.
Also note that some HTTP messages do not normally carry any content.
- Parameters:
- st - the HTTP status, for example 400 Bad Request
- Throws: IOException
- Thrown if you attempt to set the status
after using any of the methods that send content to the client.
redirect
public static native void redirect(String uri) throws IOException
- Sends a redirection response (302) to the client, causing it to
immediately fetch the target URL. The call to this method must
occur before any content is written/printed. Any further calls to
Response methods will fail after calling this.
This method is not supported for unspooled output. To send
a redirection when unspooled, you must set the 302 status
and other headers yourself, then send the headers and any
content you may want to be displayed by brain-dead browsers
that don't automatically redirect on a 302.
- Parameters:
- uri - the target URL for the client
- Throws: IOException
- Thrown if you attempt to redirect after
using any of the methods that send content to the client,
or if the output is unspooled.
noOp
public static native void noOp() throws IOException
- Sends a "no-op" (204) to the client. Normally a browser does
nothing in response, however some Microsoft browsers incorrectly
display an error alert in response. The call to this method must
occur before any content is written/printed. Any further calls to
Response methods will fail after calling this.
This method is not supported for unspooled output. To send
a no-op when unspooled, you must set the 204 status
and other headers yourself, then send the headers.
- Throws: IOException
- Thrown if you attempt to noOp after
using any of the methods that send content to the client,
or if the output is unspooled.
addExtraHeader
public static native void addExtraHeader(String name,
String value) throws IOException
- Adds an extra meta-information header to the response. The call
to this method must occur before any content is written/printed.
Example:
...addExtraHeader("X-Extra-Header", "meta info");
- Parameters:
- name - the extra header label (without the ':')
- value - the extra header value
- Throws: IOException
- Thrown if you attempt to add an extra header
after using any of the methods that send content to the client.
sendHeaders
public static void sendHeaders() throws IOException
- Immediately sends the HTTP headers to the client. This method is
usable only if the output has been unspooled. It has the same
effect as writing content, therefore all Response methods that
affect the headers will throw IOExceptions if called after sending
the headers. The header data is immediately transmitted to the
network.
You must perform all operations that affect the headers and
the HTTP status before calling this method. This includes
cookie and extra header operations, and setting the HTTP
status.
NOTE: This method is called implicitly (on unspooled
output) if any of the write/print methods are called without having
first called sendHeaders().
- Throws: IOException
- Thrown if you attempt to send headers
when the output is spooled, or after using any of the methods
that send content to the client.
- See Also:
- unspool
startErrorResponse
public static void startErrorResponse() throws IOException
- Start an HTTP "500 server error" response. This method clears any
data that may have been written to the output and replaces
it with the start of an HTTP "500 Server Error" response.
- Throws: IOException
- Thrown if there is a problem writing to
the client
- See Also:
- endErrorResponse
endErrorResponse
public static void endErrorResponse() throws IOException
- Finish off an HTTP "500 Server Error" response that was started
with startErrorResponse.
- Throws: IOException
- Thrown if there is a problem writing to
the client
- See Also:
- startErrorResponse
write
public static void write(int b) throws IOException
- Writes a byte of data
- Parameters:
- b - the byte to be written
- Throws: IOException
- Thrown if there is a problem writing to
the client
write
public static void write(byte b[]) throws IOException
- Writes an array of bytes
- Parameters:
- b - the data to be written
- Throws: IOException
- Thrown if there is a problem writing to
the client
write
public static void write(byte b[],
int off,
int len) throws IOException
- Writes a sub-array of bytes
- Parameters:
- b - the data to be written
- off - the start offset in the data
- len - the number of bytes to be written
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(String s) throws IOException
- Prints a string
- Parameters:
- s - the string (writes "null" if null)
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(char s[]) throws IOException
- Prints an array of characters.
- Parameters:
- s - the array of chars (writes 'n' 'u' 'l' 'l' '\0' if null)
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(StringBuffer sb) throws IOException
- Prints a string buffer.
- Parameters:
- sb - the StringBuffer object (writes "null" if null)
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(char c) throws IOException
- Prints a character.
- Parameters:
- c - the character to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(int i) throws IOException
- Prints an integer.
- Parameters:
- i - the integer to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(long l) throws IOException
- Prints a long.
- Parameters:
- l - the long to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(float f) throws IOException
- Prints a float.
- Parameters:
- f - the float to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(double d) throws IOException
- Prints a double.
- Parameters:
- d - the double to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(boolean b) throws IOException
- Prints a boolean.
- Parameters:
- b - the boolean to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
print
public static void print(Object o) throws IOException
- Prints an object.
- Parameters:
- o - the object to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(String s) throws IOException
- Prints a string followed by a line terminator.
- Parameters:
- s - the string to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(StringBuffer sb) throws IOException
- Prints a string buffer followed by a line terminator.
- Parameters:
- sb - the string buffer
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println() throws IOException
- Prints a line terminator
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(char s[]) throws IOException
- Prints an array of characters followed by a line terminator.
- Parameters:
- s - the array of characters to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(char c) throws IOException
- Prints a character followed by a line terminator.
- Parameters:
- c - the character to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(int i) throws IOException
- Prints an integer followed by a line terminator.
- Parameters:
- i - the integer to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(long l) throws IOException
- Prints a long followed by a line terminator.
- Parameters:
- l - the long to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(float f) throws IOException
- Prints a float followed by a line terminator.
- Parameters:
- f - the float to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(double d) throws IOException
- Prints a double followed by a line terminator.
- Parameters:
- d - the double to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(boolean b) throws IOException
- Prints a boolean followed by a line terminator.
- Parameters:
- b - the boolean to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
println
public static void println(Object obj) throws IOException
- Prints an object followed by a line terminator.
- Parameters:
- obj - the object to be printed
- Throws: IOException
- Thrown if there is a problem writing to
the client
All Packages Class Hierarchy This Package Previous Next Index