This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher and MIME types

 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

When the user selects a link, a new window is opened (with javascript) and in theory the page in the new window will contain the requested page. When I run it in Tomcat, it works perfectly. But our production server is iPlanet/Sun Web Server, and it returns the page without any content type set. Mozilla browsers will only display the pages as text instead of processing the html.

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.
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic