Reputation: 757
Favicon is put into webapp
folder.
Link in all jsp:
<link rel="shortcut icon" href="${home}/favicon.ico" />
Resources mapping in servlet config context:
<mvc:resources mapping="/favicon.ico" location="/" />
And mime description in web.xml
:
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
After that I can view favicon image via url /favicon.ico
, but i still see default tomcat favicon on browser tab. What's wrong?
Upvotes: 1
Views: 2855
Reputation: 769
try
<base href="http://www.yoursitename.com/" />
(for all relative URLs on a page)
Upvotes: 1
Reputation: 23535
Check the network log of your browser (Firebug, Chrome dev tools, etc.). You'll see exactly what request the browser issued against the server to get the favicon. I suspect this
<link rel="shortcut icon" href="${home}/favicon.ico" />
does not yield the correct URL.
In order to ensure that any potential context path is added automatically I prefer to use this in combination with the c:url
or the spring:url
JSP tags like so:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
...
<link rel="shortcut icon" href="<c:url value='/favicon.ico'/>" />
Also, usually the <mvc:resources>
piece and the MIME type declaration in web.xml
are not needed. If you told us the final layout (i.e. folder structure) of the contents of your WAR file this question would be easier to answer.
Oh, and if the favicon.ico
is in the root of your WAR file you don't even need the <link>
tag as the browser by default looks for http://server/favicon.ico
.
Did you check with more than one browser? Did you try to bookmark the page in browser (it should also load the favicon)?
Upvotes: 1