Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I set specific HTTP Content-Type encoding headers in web.xml?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With my webapp, I have plain static .css files. Is there any way I can configure web.xml so that they are delivered with an HTTP Content-Type header of "text/css;charset=UTF-8" (rather than just "text/css").

Thanks,
James
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Tomcat, the default web.xml defines the mime-mapping for files with css extension.

If you are using Tomcat, changing that entry should redefine the default content type - try it and see.

Bill
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill,

Adding...

...(just before my <welcome-file-list> element) did the trick.

Cheers,
James
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...I thought that had worked, but it hadn't. When I fixed the error in that code, making it:


then "Content-Type: text/css;charset=UTF-8" isn't sent with the response, only "Content-Type: text/css" is.

Is this the solution you meant, Bill, or have I misunderstood? Could you send me a web.xml code snippet that would make the "Content-Type: text/css;charset=UTF-8" header be sent with css files?

Thanks,
James
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, thats the only configuration setting I know of that controls content type headers.

Bill
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Bill, thanks anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic