[ Team LiB ] Previous Section Next Section

Common Request Headers

The headers you saw in Figures 4.4 and 4.5 represent the most common set of request headers you'll receive. Netscape browsers might also send an Accept-Charset request header. This section explains those headers in a little more detail.

The Accept Header

The Accept header indicates the kind of content the browser can accept. The order of the items is typically the order the browser prefers. In other words, when the browser lists text/xml before text/html it says that it prefers XML documents to HTML documents. Usually, you'll see */* at the end of the list, meaning that the browser accepts anything, but it prefers those it has already listed.

Values and Options Vary Between Browsers

graphics/bytheway_icon.gif

Figure 4.4 was produced using Mozilla and Figure 4.5 using Internet Explorer. Although the browsers won't vary from the protocol requirements, the values and optional elements are quite a bit different. For example, notice all of the Microsoft applications Internet Explorer is willing to accept.


If you look at the Accept header sent by a wireless phone, you'll see that it lists HTML text and bitmap images after the */*, indicating that it prefers just about anything to HTML or bitmaps! Here is the Accept header sent from a wireless phone:


Accept: application/x-hdmlc, application/x-up-alert, application/x-up-cacheop,
   application/x-up-device, application/x-up-digestentry, text/x-hdml;
           version=3.1,
   text/x-hdml;version=3.0, text/x-hdml;version=2.0, text/x-wap.wml,
   text/vnd.wap.wml, */*, image/bmp, text/html

The Accept-Language Header

The Accept-Language header gives you a hint as to what language the browser prefers (actually, the browser's user, because the browser doesn't speak human languages). For English, you might see just en or you might see en-us or en-uk specifying English for a particular locale such as the United States or the United Kingdom. You can use this header to provide language-specific content automatically. You'll learn more about this idea in Hour 22, "Internationalization."

The Accept-Charset Header

If present, the Accept-Charset header indicates the preferred character set(s) that the browser accepts. For Netscape running in an English-speaking locale, you'll most likely see this kind of header:


Accept-Charset: iso-8859-1,*,utf-8

The User-Agent Header

Of all the headers sent by the browser, the User-Agent header is probably the most useful because it indicates what kind of browser is making the request. Oddly, both Netscape and Internet Explorer identify themselves as Mozilla, which was the nickname for the early Netscape browser. (There is now a browser called Mozilla, which was born from the code for Netscape 5.)

Mozilla—A Monster Browser

graphics/bytheway_icon.gif

In case you're wondering where the name Mozilla came from, Netscape was founded by the folks who wrote the old Mosaic Web browser. Netscape Navigator was intended to be a monstrous version of Mosaic: the Godzilla Mosaic, or Mozilla.


When Internet Explorer (IE) first came out, it lagged behind Netscape in usage, and gradually added features to become a reasonable alternative by the time IE version 3 came along. By identifying itself as Mozilla-compatible, IE is telling the Web server that it can handle anything Mozilla can.

If you want to figure out whether the browser is Netscape or IE, only IE sends the MSIE string as part of its User-Agent header. Thus, you can do the following test in your JSP or servlet:


if (request.getHeader("USER-AGENT").
    indexOf("MSIE") >= 0)
{
    // do Internet Explorer specific stuff here
}
else
{
    // do Netscape specific stuff here
}

You can perform similar tests to detect other browsers, such as Opera.

In Case of Trouble

graphics/bytheway_icon.gif

If you are having trouble seeing request headers you are expecting, see the "Q&A" at the end of this hour.


    [ Team LiB ] Previous Section Next Section