File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Headers, Mime Type, and Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Headers, Mime Type, and Session" Watch "Headers, Mime Type, and Session" New topic

Headers, Mime Type, and Session

Andrew Esse

Joined: Aug 27, 2004
Posts: 18
I am writing a servlet that locates a document based on a string sent as a request parameter. Based on this string, I create an input stream to the document and write the resulting byte[] array to the response's output stream. I also determine the Mime Type and set that in the request.

The issue that I am having is that when I attempt to run the servlet in IE, I get an error the first time I run it in a particular instance of IE (but it works fine after the first try). Debugging the code, I noticed that the first time I run the servlet, I begin with 0 Headers in the response object with a count of 0. After I get the Session from the request object, there become 3 Headers in the response object that are all initialized with a count of 3. When I set the content type, a fourth header is added and when I write the output stream, a fifth is added, bringing the count to 5.

In subsequent runs (same IE instance), before I get the Session from the request, there are already 5 headers, but all are zeroed out and the count is 0. After I set the Content Type, the first header gets initialized and when I write the output stream, the second header gets initialized and the count becomes 2. I was wondering if anyone could help me determine why this occurs and how to prevent it in the future. The IE error message I get is that IE could not download 'filename' from 'servername'.

If it helps, this doesn't happen when trying this on Firefox and it also doesn't happen when viewing image files (tiff/jpg/etc.)
[ October 12, 2004: Message edited by: Andrew Esse ]
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
I'd get out a packet sniffer and see exactly what the headers are as they are being sent across.

For firefox, this is easy to do with the live headers plugin, but for ie, you will need a packet sniffer.
I agree. Here's the link:
subject: Headers, Mime Type, and Session
It's not a secret anymore!