[ Team LiB ] |
![]() ![]() |
Common Response HeadersIf you look all the way back to Figure 4.1, you'll see a typical response sent by a Web server. There are many variations of response headers, but relatively few that you need to worry about when you write Java Web applications. The Content-Type HeaderThe Content-Type header is the most important response header. It tells the browser how to interpret the data it receives. A JSP has a default content type of text/html, although you can use a JSP page directive to change the content type. If you are returning XML data, for instance, you use a content type of text/xml. The Content-Length HeaderThe Content-Length header is important for many types of content that contain binary data. It tells the browser exactly how many bytes are in the body of the response. That way the browser can read the full response without worrying about whether it has received everything. The Cache-Control HeaderThe Cache-Control header allows you to control how long the browser keeps a particular page cached. As you saw in Figure 4.1, a JSP normally isn't cached at all. You can request that a page be cached for 5 minutes (300 seconds) by using the following response header: Cache-Control: maxage=300 Should I Remember You?
|
[ Team LiB ] |
![]() ![]() |