Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IE ignoring setContentType?  RSS feed

 
Marc Santiago
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JSP page sets the content type via a response.setContentType("application/xml") call. However, when I browse the page in IE 6.0, it says "type: not available". I've confirmed on the server side that it is indeed sending application/xml as the content type in the header. Anyone else ever see this happen before?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've confirmed on the server side that it is indeed sending application/xml as the content type in the header.

What did you do to confirm this?
And, are you sure that you are setting the content type prior to emitting any output?
 
Marc Santiago
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to confirm the headers by reviewing the debug messages in the server log.
And yes, I'm sure I am setting the content type prior to writing anything out. I thought that might have been it at first as well, so I rewrote my JSP to buffer all of my output into an ArrayList, call setContentType, and then feed the ArrayList into out.println(). Same result (type not available).
Interestingly enough, when I take out the guts of my JSP and replace it with a basic out.println("foo"), I get the correct content type. All I'm doing in this app is accepting a directory name from the user, reading in all the files in the directory, and redirecting the contents back out to the browser. The only call I make to the response object is with the setContentType call.
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double check the content type is being sent by using Mozilla and installing the livehttpheaders plugin. This will display the request/response headers the browser is getting.
That said, IE intentionally ignores content headers. This is an intentional "feature" which MS calls datasniffing, but it opens up users to scripting attacks. Opera 6 has a similar problem, but you can check a box to get it to obey content-type (why isn't this the default?!).
Make sure you have the two header lines XML requires, the first defining the document as XML and the second the DTD, so hopefully IE's sniffer knows it's XML.
Personally I find this annoying as some sites don't set the content type to text/html, as the value text/plain looks fine in their copy of IE.
MS explanation of feature:
http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
Security bug:
http://www.securitytracker.com/alerts/2002/Feb/1003540.html
http://www.securiteam.com/securitynews/5FP0F1P6AK.html
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make sure that your output content is xml format
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure whether this will help, but u can try adding <mime-mapping> in ur web.xml
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set content-type to text/xml instead of application/xml and see what happens.
IE does NOT ignore contenttype, though it may ignore some. In this case IE doesn't recognise the contentype application/xml (or rather it is no built-in contenttype and there is no registered application on the machine that can handle it and plugs into IE).
[ January 30, 2004: Message edited by: Jeroen Wenting ]
 
Marc Santiago
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I've confirmed that we are getting the headers correctly using livehttpheaders (neat tool, that!). I've also tried setting content type to text/xml and then text/html, but I still keep getting "type not available".
Here's my code. Am I missing something obvious?

[ January 30, 2004: Message edited by: Marc Santiago ]
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure you need to include a reference to a DTD.
Rick DeBay
P.S. From a developers perspective IE does ignore content-type, if it changes it whenever it feels the server has misidentified the type. It should only do "datasniffing" if the header is missing.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that it burbs about the .xml extension used for the xsl stylesheet rather than the xml you generate.
Either that, or the XML you generate is malformed in some way and IE tries to find out what to parse it as if not XML (and of course fails).
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
set content-type to text/xml instead of application/xml and see what happens.

check the accept-encoding header.
And good call on the .xsl extension. I think I remember reading about an IE bug with .xml for xsl stylesheets somewhere... was it Java & XSLT?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!