`

Web.xml.MimeMapping

    博客分类:
  • java
阅读更多

<mime-mapping>

This tag defines a mapping between a file extension and a MIME type.

The server-default web.xml file in <jakarta>/conf/web.xml contains a list of all the built-in mappings. This tag can be used to extend that list.

There are two required subelements as follows:

  • <extension > - file extension (no leading dot), examples: xls, pdf
  • <mime-type > - a mime type, eg: application/vnd.ms-excel or text/html

Enabling file downloads via the application/octet-stream MIME type

While most files will download correctly from your site, if you have created a file with an unknown extension, the browser may attempt to display the file using the text/plain MIME type, which will show in the browser as text.

To avoid this behaviour, a mime-mapping can be set for your file to force the browser to download the file. This appropriate MIME type is application/octet-stream. This is a generic type for binary data streams.

Here is an example for an imaginary file type of pqz:

<!-- Send PQZ files as application/octet-stream so the user is asked to download the file --> 
<mime-mapping>
<extension>pqz</extension>
<mime-type>application/octet-stream</mime-type>
</mime-mapping>

Enabling download of Microsoft Excel spreadsheets

When providing Microsoft Excel spreadsheets for download from your application, some browsers display the file as garbage on the browser unless an appropriate mime-mapping is set.

The desired action, is to prompt for the file to be saved, or to open it in Excel. Newer versions of Internet Explorer may also display the file directly in the browser using the embedded Excel Active-X control.

Adding the following mime-mapping element to web.xml sets the correct mime-type, allowing the browser to interpret the file correctly.

<!-- Set Excel mime-mapping so spreadsheets open properly instead of being sent as an octet/stream -->
<!-- If this is not done, the user may be prompted to save the file, or it may open as garbage text in the browser -->
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>

The MIME type used here is vendor-specific (in this case Microsoft), so it has a "vnd." prefix.

Enabling a Favourites Icon

In Internet Explorer, when the URL you are visiting is in your Favourites List, an icon appears next to the URL in the Address bar and next to the website name in the Favourites menu. To see an example, add this page to your Favourites, then refresh. Look at the address bar of the browser, the metawerx logo is displayed. In FireFox the icon is always displayed.

http://www.metawerx.net/images/screenshots/favourites_icon.png

This icon is called the Favourites Icon, and can be customised by creating a 16x16 or 32x32 Windows Icon file, with an extension of .ico, and uploading it to the root folder of your website as "favicon.ico". You can download other site's icons by going to http://website/favicon.ico. For example: http://wiki.metawerx.net/favicon.ico .

Note that you may need special graphics software to create or edit an icon file, as most graphics software does not support this format. One such piece of software is IrfanView . However - see below for how to use a PNG file instead.

The Favourites Icon has a file type of image/x-icon. This is not defined by default in the Tomcat configuration.

Add the following mime-mapping element to web.xml sets the correct mime-type, allowing the browser to interpret the file correctly.

<!-- Set Favourites Icon MIME-Type --> 
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>

On modern browsers, a newer method for adding a favourites icon has been added. This method now takes preference over the default favicon.ico file. Therefore, for best results on your web pages, include the following line in your HTML as well. For compatibility with older browsers however, we recommend using the favicon.ico method.

<link rel="icon" type="image/ico" href="/favicon.ico"/>
  • Using a link in this way also allows different icons for different pages of your site
  • You can also use a PNG image by using image/png above instead of image/ico.
  • href can point to any valid image location, as long as the image is the correct type (ico if you specified image/ico, png if you specified image/png etc..) and size (16x16 or 32x32)
分享到:
评论

相关推荐

    在web.xml中引入其他xml配置文件的步骤

    ### 在web.xml中引入其他XML配置文件的步骤 在Java Web开发中,`web.xml`作为Web应用程序的核心配置文件,负责定义应用级别的配置信息。为了提高代码的可维护性和复用性,有时需要将一部分配置内容提取到独立的XML...

    web.xml配置详解, web.xml web.xml 配置实例

    Web.xml 配置详解 Web.xml 是一个部署描述符文件,用于描述 Web 应用程序的配置信息。该文件是基于 XML 语法的,所有的元素都是大小写敏感的。下面是 web.xml 配置文件的详细解释: 定义头和根元素 在 web.xml ...

    在web.xml中配置action或.do

    ### 在web.xml中配置action或.do的理解与实践 #### 一、引言 在Web开发领域,特别是基于Java的Web应用程序开发中,`web.xml`文件扮演着至关重要的角色。它不仅定义了Web应用的基本配置,还管理着诸如Servlet、过滤...

    详解Spring mvc的web.xml配置说明

    在构建基于Spring MVC的Web应用程序时,`web.xml`配置文件扮演着至关重要的角色。它定义了应用程序的行为,包括启动时的初始化、请求处理以及中间件的设置。下面我们将详细探讨`web.xml`中涉及Spring MVC的主要配置...

    Maven工程的web.xml模板

    由于经常使用Maven创建web工程所以需要使用web.xml默认模板

    为tomcat服务器配置https,tomcat需要设置的server.xml与web.xml配置

    在Tomcat的`conf`目录下,有两个主要的XML配置文件:`server.xml`和`web.xml`。`server.xml`是Tomcat的主要配置文件,而`web.xml`则定义了应用程序的行为。 在`server.xml`中,我们需要配置`&lt;Connector&gt;`元素来启用...

    log4j与web.xml的配置

    Web.xml是Servlet容器(如Tomcat)的部署描述符,用于配置Web应用程序的各种设置,包括日志配置。本文将详细讲解如何将Log4j整合到Web应用并通过web.xml进行配置,以实现日志信息的输出和管理。 1. **Log4j介绍** ...

    web.xml 中的listener、 filter、servlet 加载顺序及其详解.doc

    Web.xml 中的 listener、filter、servlet 加载顺序及其详解 在 Web 应用程序中,web.xml 文件扮演着非常重要的角色,它定义了 Web 应用的结构和配置。其中,listener、filter、servlet 是三个非常重要的概念,它们...

    javaweb项目中web.xml的作用

    javaweb项目中web.xml的作用 web.xml是javaweb项目中一个非常重要的配置文件,它是每一个javaWeb工程都必需的配置文件。web.xml文件的主要作用是用于初始化工程配置信息,例如welcome页面、filter、listener、...

    jboss-web.xml jndi.properties oracle-ds.xml

    首先,"jboss-web.xml"是JBoss特定的Web应用程序部署描述符,它是Tomcat中的web.xml在JBoss环境中的扩展。这个文件主要负责定义应用的Servlet、过滤器、监听器以及与EJB交互的JNDI(Java Naming and Directory ...

    struts.xml和applicationContext.xml、web.xml的配置

    在Java Web开发中,`struts.xml`, `applicationContext.xml` 和 `web.xml` 是三个至关重要的配置文件,它们各自负责不同的职责,并协同工作来构建一个完整的应用框架。以下是关于这三个配置文件的详细说明。 首先,...

    演示web.xml文件中error-page标签的使用.zip

    在Java Web应用中,`web.xml`文件是部署描述符(Deployment Descriptor),它定义了应用程序的行为、组件配置以及服务器如何处理请求和响应等关键信息。`error-page`标签是`web.xml`中的一个重要元素,用于处理HTTP...

    web.xml各种配置

    web.xml是Java Servlet规范定义的一个部署描述文件,用于配置Java Web应用程序。它遵循XML的规则,必须有一个唯一的根节点,大小写敏感,并且标签需要严格配对。在大型Web工程中,web.xml文件非常重要,因为它提供了...

    web.xml配置详解.pdf

    web.xml 各属性作用描述 Web.xml 常用元素 &lt;web‐app&gt; ‐name&gt;‐name&gt;定义了WEB 应用的名字 &lt;description&gt;&lt;/description&gt; 声明WEB 应用的描述信息

    web.xml加载顺序与web.xml常用节点解析

    `web.xml`是Java Web应用程序的核心配置文件,用于定义应用服务器如何初始化和管理Web应用程序。它遵循Java Servlet规范中的标准,为开发者提供了一种结构化的方式来配置Servlet、过滤器、监听器和其他组件。理解`...

    servlet的写登陆管理系统用到的web.xmlweb.xml

    servlet的写登陆管理系统用到的web.xml

    WEB-INF中的web.xml中之前增加以下配置:

    WEB-INF中的web.xml配置详解 本文将详细介绍WEB-INF中的web.xml文件中的配置,包括Context配置、Resource配置、resource-ref配置,以及对应的Java类编写。 一、Context配置 在WEB-INF中的web.xml文件中,添加以下...

    web.xml配置详解

    web.xml 配置详解 web.xml 是一个 XML 文件,用于描述 Servlet/JSP 应用的各个方面的元素,如 servlet 注册、servlet 映射以及监听器注册。下面是 web.xml 文件的详细解释: XML 头 web.xml 文件以 XML 头开始,...

    SpringMVC基于代码的配置方式(零配置,无web.xml)

    传统的SpringMVC配置往往依赖于XML文件,如web.xml和spring-servlet.xml等,但随着Spring框架的发展,出现了基于代码的配置方式,实现了零XML配置,提高了开发效率。本文将详细介绍如何在不使用web.xml的情况下,...

    spring在web.xml中和在struts中的不同配置..pdf

    在本文中,我们将探讨Spring在`web.xml`中的配置与在Struts中的配置差异,以及这两种配置方式背后的基本原理。 首先,Spring的核心是ApplicationContext,它是一个管理Bean的容器,可以看作是应用程序的上下文环境...

Global site tag (gtag.js) - Google Analytics