13

I have had a really hard time getting my 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" />
Roosh
  • 651
  • 1
  • 8
  • 16
  • 2
    You realise that `favicon.ico` has to go in the root path, right? i.e. `/favicon.ico`, not `/ui/favicon.ico`. – skaffman Mar 10 '11 at 15:25
  • Which AppServer or Web Server are you using? – adarshr Mar 10 '11 at 15:25
  • @skaffman - That's archaic. The [new W3C recommendation](http://www.w3.org/2005/10/howto-favicon) doesn't have any such restriction. – adarshr Mar 10 '11 at 15:27
  • @adarshr: Archaic it may well be, but it might also be the issue. – skaffman Mar 10 '11 at 15:29
  • @skaffman - agree, favicons have always been a pain. @userXXX - best way to rule out such issues is to directly invoke the URL http://yoursite.com/context/path/name.ico in a browser, rather than depending on it being rendered in the favicon area. – adarshr Mar 10 '11 at 15:31
  • Sorry guys, I forgot to add that detail. As part of troubleshooting the issue, I copied the favicon into the webapp root directory and still got no results. I think part of the problem is due to spring being mapped to the root path as well. – Roosh Mar 10 '11 at 15:49
  • @skaffman I'm using tomcat 6 to host the application. – Roosh Mar 10 '11 at 15:51
  • 3
    Check if there are any MIME settings required for ICO extensions on Tomcat. – adarshr Mar 10 '11 at 17:43
  • 1
    @skaffman That worked! Thanks for your help! I will post the official answer. – Roosh Mar 10 '11 at 19:07

1 Answers1

14

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!

Roosh
  • 651
  • 1
  • 8
  • 16