Setting Arbitrary Response
Headers
public void
setHeader
(String headerName,
String headerValue)
Sets an arbitrary header
public void setDateHeader(String name,
long millisecs)
Converts millis since 1970 to date in GMT format
public void setIntHeader(String name,
int headerValue)
Prevents need to convert int to String
addHeader, addDateHeader, addIntHeader
Adds header instead of replacing
59
Servlets
www.corewebprogramming.com
Setting Common Response
Headers
setContentType
Sets the Content Type header.
Servlets almost always use this header.
See Table 19.1 (Common MIME Types).
setContentLength
Sets the Content Length header.
Used for persistent HTTP connections.
See Connection request header.
addCookie
Adds a value to the Set Cookie header.
See separate section on cookies.
sendRedirect
Sets Location header (plus changes status code)
60
Servlets
www.corewebprogramming.com
30