Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

HTTP Response Headers methods

Hi,

I was reading as follows







HTTP allows multiple occurrences of the same header name, and you sometimes want to add a new

header rather than replace any existing header with the same name. For example, it is quite common to

have multiple Accept and Set-Cookie headers that specify different supported MIME types and different

cookies, respectively. With servlets version 2.1, set- Header, setDateHeader and setIntHeader always add

new headers, so there is no way to “unset” headers that were set earlier (e.g., by an inherited method).

With servlets version 2.2, setHeader, setDateHeader, and setIntHeader replace any existing headers of the

same name, whereas addHeader, addDateHeader, and addIntHeader add a header regardless of whether a

header of that name already exists. If it matters to you whether a specific header has already been set, use

containsHeader to check. Finally, HttpServletResponse also supplies a number of convenience methods for

specifying common headers.






setDateHeader(String header, long milliseconds)
             This method saves you the trouble of translating a Java date in milliseconds since 1970 (as returned by System.currentTimeMillis, Date.getTime, or Calendar.getTimeInMillis) into a GMT time string.

 setIntHeader(String header, int headerValue)
              This method spares you the minor inconvenience of converting an int to a String before inserting it into a header.


• setContentType

    This method sets the Content-Type header and is used by the majority of servlets.

• setContentLength

This method sets the Content-Length header, which is useful if the browser supports persistent (keep-alive) HTTP connections.

• addCookie

This method inserts a cookie into the Set-Cookie header. There is no corresponding setCookie method, since it is normal to have multiple Set-Cookie lines.

• sendRedirect

the sendRedirect method sets the Location header as well as setting the status
code to 302.


Please advise.

Any links resources ideas highly appreciated. Thanks in advance
Avatar of girionis
girionis
Flag of Greece image

What exactly is the question?
Avatar of gudii9

ASKER

When to use which header method and how they are different from servlet 2.1 vs servler 2.2. Please advise
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial