MS Office 2007+使用 IE7+ 在 JSF 上下载静态文件
得到这个代码:
<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>
这个代码对于 FF 工作正常,但 IE 认为这是一个 zip 文件。为什么?
在这里找到 mime 类型 为 Excel 文档设置 mime 类型 但不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从技术上讲,只有 servletcontainer 自己的
web.xml
中列出的 mime 类型(例如 Tomcat 中的/conf/web.xml
)才能基于以下内容进行识别和支持:文件扩展名。.xlsx
扩展相对较新,较旧的 servlet 容器不支持。不过,您可以在 web 应用程序的/WEB-INF/web.xml
中定义自定义 mime 类型:如果您对 servlet 容器具有完全的管理控制权,您当然也可以将其添加到那里,例如 Tomcat 的 < code>/conf/web.xml 文件。
它在 FF 中工作是因为当 HTTP
Content-Type
文件下载的响应标头缺失或过于通用。您在那里找到的相关问题仅适用于
.xls
文件(并且默认情况下已经受到大多数当前 servlet 容器的支持)。您可以在此处找到所有新 Office 2007 OpenXML 文件 mime 类型的概述:http://filex.com/faq /office_mime_types.phpTechnically, 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
: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