开发者

Spring mvc:resource not finding *.ico files

I have had a really hard time getting my开发者_如何学C Spring 3.0 application to recognize favicon.ico type files as a resource. I have defined my resource directory in my spring-context.xml file as follows:

<mvc:resources mapping="/ui/**" location="/ui/" />

This directory structure looks like:

/ui
  /images
  /styles
  /scripts
  ...

Spring hosts my images, scripts, and styles just fine. However, I get a 404 error when trying to retrieve any *.ico files in the images directory. All PNG, GIF, and JPG images work just fine in that same directory. I tried being more specific on which directories to host and even specified .ico files as resources in the context.xml file and still get the same results:

<mvc:resources mapping="/ui/images/*.ico" location="/ui/images" />

I've also tried adding a servlet mapping to the default servlet. This seemed to work for some when I researched online, but has not proven successful for me.

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.ico</url-pattern>
</servlet-mapping>

EDIT: I have also added the favicon.ico file to the root path of the web app. If I use a png file for the favicon, it works in every browser but IE. I would like to solve this problem for all browsers if possible. Any help at this point would be greatly appreciated.

EDIT2: I already have a link tag in the XHTML document:

<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/ui/images/favicon.ico" />


The solution for me, since I was using Tomcat 6 to host the application, was to add the MIME type to the web.xml file of the application as shown below.

<mime-mapping>
    <extension>ico</extension>
    <mime-type>image/vnd.microsoft.icon</mime-type>
</mime-mapping>

Thanks skaffman!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜