I have run in to a problem with RequestDispatcher not always setting the MIME type.
In the application I am supporting, a user has a list of links that point to a servlet front-end controller. The controller uses the request parameters as well as some session info to determine which page is appropriate, and then uses RequestDispatcher to forward the request to that page.
If I explicitly set the content type on the response object before forwarding the request, it works fine... but I know this is not a good solution, as you should never commit anything to the response before forwarding it. Has anyone else run into this type of problem?
One other thing, the problem with the content type only happens when the requested resource is an html page. If it is a jsp page, it works fine, and if it is a pdf file it works fine. I could convert every html page into a jsp, but that would involve changing the file extension on 300+ MB of html. Plus, new content is being added frequently by our web development team, and I don�t want to have to police them constantly to make sure an html page doesn�t slip in there. Thanks in advance.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Well, you could set the content-type in the HTML itself with a meta tag. This would still mean you have to change all HTML files and police everyone so that no page goes without the meta tag:
But maybe you don't have to change the HTML files at all. Just try to add this to your web.xml:
Good luck [ June 15, 2005: Message edited by: Henrique Sousa ]
Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Joined: May 24, 2004
Thanks for the quick reply Henrique,
I looked at some of the html pages that are being requested, and they actually do contain the following tag:You would think that this would alleviate the problem, but it doesn't... I seem to remember something about mime-mapping as well. Thanks for reminding me, and I will also look to see if that is a possibility.