For years (literally over 2 years) my company has been dealing with an issue where after loging into the intranet using any Mozilla browser (including Netscape and Firefox), it would direct you to the favicon.ico rather than the home page. We are using a protected Java Servlet on a JBoss server to serve up the intranet pages. If the favicon was not present, it would give a 404 error or would say it had not been defined. I’ve spent hours trying to solve the problem, mostly by trial and error, renaming files, adding link data to the head of the index page and everything else I could think of.
Today, however, I finally found the solution!
The problem does not lie in the index page, but rather in the login page. Mozilla browsers automatically look for the favicon.ico in the root directory if there is no link tag in the head of your document. When you attempt to access any protected page without logging in you are directed to the login page. Mozilla is looking for the favicon on the login page and the favicon is protected so it theoretically redirects you again to the login page so that you can access the favicon for the login page. Hence when you log in, you do access the favicon and not the page you were looking for in the first place.
To combat this problem, you need to set up an unprotected directory where the favicon resides and place the following code on your login page:
<link rel="icon" href="unprotected/favicon.ico" type="image/ico">
<link rel="shortcut icon" href="/unprotected/favicon.ico">
This tells the browser to look for the favicon in a location other than the default root directory. Problem solved!









Very useful.. thanks. But its working in FireFox not in Internet Explorer. Do you know how to get it work in IE ?
The problem for me never existed in Internet Explorer, it always worked fine except in Mozilla (FireFox).
Sorry to mention about my problem…
My problem is to display an Icon in the browser for my web application. I added ur code in my index.jsp and it worked in FireFox.
Now I want it to work in Internet Explorer also. Do you know a solution for this?
Have you tried putting favicon.ico into your web root directory? That’s what most browsers look for by default.
Awsome work!!! It saved me a lot of time.Thanks for the solution
Another way to turn around the firefox-favicon problem: make a copy of index.htm and then rename it as favicon.ico
Here is what I think the *right* way to handle this is. The other ways will work, but they strike me as a bit hackish. Just add an empty security constaint into your web.xml file for favicon.ico. Here is a sample
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire App</web-resource-name>
<url-pattern>/favicon.ico</url-pattern>
</web-resource-collection>
</security-constraint>
By leaving the <auth-constraint> tag out, anyone is allowed to access this file. You may say, now wait, this URL matches the “/*” URL above, BUT tomcat processes the constraints for a URL from most specific to least, so /favicon.ico overrides /*.