tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Tomcat issue : open a office 2007 document
Date Sat, 16 Jan 2010 15:43:55 GMT
soulSnatched wrote:
> I am trying to open a office 2007 document a .xlsx file 
> I am using  tomcat 6.18 on Windows XP platform
> Currently i am using 
> in my jsp:
> response.setContentType("application/"); 
> and the mime mapping in tomcat/conf/web.xml is defined as : 
> <mime-mapping>
>         <extension>xls</extension>
>         <mime-type>application/</mime-type>
>     </mime-mapping>
> It opens fine in excel 2003 but with an annoying pop up...
> but i need it to open it in excel 2007
> so i made the following changes but its not working 
> jsp:
> response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
> mime mapping in web.xml
> <mime-mapping> 
> <extension>xlsx</extension> 
> <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>

> </mime-mapping> 
> it opens but with an error saying 
> "Excel cannot open file 'xxx' because the file format or file extention is
> not valid. verify that the file has not been corrupted or that the file
> extension matches the format of the file" 

The very first thing to say, is that this is most probably (99.99%) not 
a Tomcat issue.
Since you are under Windows, I will presume that you are using IE as a 
browser.  If that is the case, the first thing you should do is to get 
an IE add-on that allows you to see exactly what you are sending and 
receiving between the browser and the webserver (Tomcat in this case, 
but only incidentally).
(One such add-on for IE is called Fiddler-2; if you are using Firefox, 
try LiveHttpHeaders or HttpFox).
Then activate this plugin, and click on the corresponding link again 
(the one which should open the Excel).  You will then see in the plugin 
window, what your browser is sending, and what it is receiving.
Look in the received HTTP headers, for a header named "Content-type". 
If your Tomcat setup above works, you should see what you set in 
If that is the case, then Tomcat is doing its job, and your problem is 
Understand that Tomcat is not sending the document directly to Excel.
Tomcat is sending the response, which contains the sheet as a body, to 
the browser.  It is the browser then (in function of its setup, or the 
Windows setup) which decides to call one program or the other to 
display/process this file.
Maybe your browser is not calling the correct version of Excel ?

Also, separately, if you are using IE :
The HTTP protocol indicates that when the server sends a response with a 
certain Content-type, the browser SHOULD NOT attempt to "second-guess" 
the server.  It should believe what the server says, and react accordingly.
However, in their wisdom, MS IE developers don't give a damn about what 
HTTP says, and always try to second-guess the server.  IE (differently 
in each version of IE and each version of Windows) examines the content 
received, and decides by itself what this is.
In other words, it basically ignores the Content-type sent by the server 
and chooses a MIME-type itself.
This behaviour has caused endless frustration to web developers over the 

For more information on this subject, search Google for "IE and MIME", 
it is very educative.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message