How can I output favicon <link> in HTML header section using JSF 2.0?

Using h: outputStylesheet I can embed CSS resources in the HTML head section, but how can I create a <link> for the favicon of an image resource that displays HTML, as in this example:

HTML output:

 <head> ... <link rel="icon" type="image/png" href="favicon.png" /> ... </head> 

The image resource is located in <web>/resources/images .

If I use direct HTML in the JSF template, for example href="/resources/images/favicon.png" , the resource was not found - switching to /resources/images/favicon.png leads to an error

/resources/images/favicon.png/index.jsf not found

(I set index.jsf as the index page in web.xml, which could explain this way)

+7
source share
2 answers

Your webapp seems to be working on a non-empty path. The leading slash / leads you to the root of the domain. Use #{request.contextPath} to dynamically insert the context path.

 <link rel="shortcut icon" type="image/png" href="#{request.contextPath}/resources/images/favicon.png" /> 

(note that I installed rel to make it compatible with crossbrowser)

+10
source

href="/resources/images/favicon.png" really looks in your server’s root directory for http: //localhost/resources/images/favicon.png , and not inside your web application directory.

In your href location, you will need to specify the web application directory href="/webappname/resources/images/favicon.png" http: //localhost/webappname/resources/images/favicon.png


If your .xhtml file is in the same directory as your resource folder, then deleting the slash should work. href="resources/images/favicon.png"

+2
source

All Articles