la00
la00

Reputation: 301

MS Office 2007+ static file download on JSF with IE7+

Got this code:

<h:outputLink title="#{msg.fileUpload_template_file}" styleClass="FormSubmitNoColor" type="application/vnd.ms-excel" value="#{facesContext.externalContext.requestContextPath}/resources/csvTemplates/02_myfile_V1.xlsx" >#{msg.fileUpload_template_file}</h:outputLink>

This code work fine for FF but IE thinks this is a zip file. why?

Found the mime type here Setting mime type for excel document but doesn't work to.

Upvotes: 1

Views: 355

Answers (1)

BalusC
BalusC

Reputation: 1108802

Technically, only the mime types which are listed in servletcontainer's own web.xml (such as the /conf/web.xml one in Tomcat), are recognized and supported based on the file extension.

The .xlsx extension is relatively new and not supported by older servletcontainers. You can however define custom mime types in your webapp's /WEB-INF/web.xml:

<mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping>

If you have full admin control over the servletcontainer, you can of course also add it over there, such as Tomcat's /conf/web.xml file.

That it works in FF is because FF will determine by itself based on the file extension against the client-specific mime type mapping ("file associations" as it is called in Windows), when the HTTP Content-Type response header of the file download is absent or overly generic.

The related question which you found there applies to .xls files only (and is already by default supported by most of the current servletcontainers). You can find an overview of all new Office 2007 OpenXML file mime types here: http://filext.com/faq/office_mime_types.php

Upvotes: 1

Related Questions