Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Excel 2007 and charset getting appended to ContentType response Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Excel 2007 and charset getting appended to ContentType response Header" Watch "Excel 2007 and charset getting appended to ContentType response Header" New topic
Author

Excel 2007 and charset getting appended to ContentType response Header

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
While downloading Excel documents both 2003 (xls) and 2007 (xlsx) I am getting a warning message pop-up with "Yes"\"No"

The file you are trying to open, 'download.do' is in a different format than specified by the file extension. Verify that the file is not corrupted and is from
a trusted source before opening the file. Do you want to open the file now?


Though I set the content type header with application/vnd.ms-excel (excel 2003) and application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (excel 2007), I see charset=UTF-8 is appended automatically to the content type header.

Content Type Header: application/vnd.ms-excel; charset=UTF-8

Am I getting the warning message because of the charset being appended at the end of the content type header? If yes, is there a way to remove it?

Any help would be greatly appreciated?
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
After some research, I found the issue is not with the charset getting appended to the content type.

As the warning message states, the browser couldn't recognize the extension. So based on the file extension, I dynamically appended the extension.

Example:

.do for all types of files like jpg, pdg, doc, docx, txt, html

replace the .do with .xls(or).xlsx based on the file extension of the attached file. In this way browser does not throw the warning message and opens the xl file.

Put the .xls and .xlsx mappings in web.xml for action class.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Excel 2007 and charset getting appended to ContentType response Header
 
Similar Threads
how to save web page in Excel file to client's local?
Opening Excel sheet in a browser
The IE and Netscape conflict again!! :-)
Opening excel sheet separately
sql to excel with java character problem.