Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
7.2 HTTP 1.1 Response Headers and Their Meaning
145
setContentType
This method sets the 
Content Type
 header and is used by the 
majority of servlets. See Section 7.5 (Using Servlets to Generate 
GIF Images) for an example of its use.
setContentLength
This method sets the 
Content Length
 header, which is useful 
if the browser supports persistent (keep alive) HTTP 
connections. See Section 7.4 for an example.
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. See Chapter 8 for a 
discussion of cookies.
sendRedirect
As discussed in the previous chapter, the 
sendRedirect
method sets the 
Location
 header as well as setting the status 
code to 302. See Section 6.3 (A Front End to Various Search 
Engines) for an example.
7.2 HTTP 1.1 Response Headers 
and Their Meaning
Following is a summary of the HTTP 1.1 response headers. A good under 
standing of these headers can increase the effectiveness of your servlets, so
you should at least skim the descriptions to see what options are at your dis 
posal. You can come back to get details when you are ready to make use of
the capabilities. Note that Appendix A (Servlet and JSP Quick Reference)
presents a brief summary of these headers for use as a reminder.
These headers are a superset of those permitted in HTTP 1.0. For addi 
tional details on these headers, see the HTTP 1.1 specification, given in RFC
2616. There are a number of places the official RFCs are archived on line;
your best bet is to start at 
http://www.rfc editor.org/
 to get a current
list of the archive sites. Header names are not case sensitive, but are tradi 
tionally written with the first letter of each word capitalized.
Be cautious in writing servlets whose behavior depends on response head 
ers that are only available in HTTP 1.1, especially if your servlet needs to run
on the WWW  at large,  rather than on an intranet many older browsers
support only HTTP 1.0. It is best to explicitly check the HTTP version with
request.getRequestProtocol
 before using new headers.
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved