将favicon添加到JSF项目并在< link>中引用它 [英] Add favicon to JSF project and reference it in <link>
问题描述
如何将一个favicon添加到一个JSF项目并在< link>
元素中引用它?
我试过如下:
< h:head>
< link rel =icontype =image / x-iconhref =images / favicon.ico/>
...
< / h:头>
然而,它没有显示任何图标。
相对 href
是相对于当前的请求URI。它可能解析为无效的URL。您需要预先设置上下文路径,以便它相对于域根。
另外, rel
最好是快捷方式图标
,以使其在旧版浏览器中也能正常工作。
如果使用 .ico
文件,您还需要确保它是真实的 .ico
文件,而不是一些 .bmp
重命名为 .ico
。您可以根据多种图像格式生成一个此处。但是,您也可以使用 .png
或 .gif
文件。
总而言之,前提是文件位于 $ b
WebContent
| - 图片
| ` - favicon.ico
:
然后这样做:
< link rel =shortcut icontype =image / x-iconhref =#{request.contextPath} / images / favicon.ico的/>
如果您将它作为JSF资源放置在 / resources中文件夹如下
$ b
WebContent
| - resources
| ` - 图片
| ` - favicon.ico
:
可以通过<$ c $访问c>< h:graphicImage name =images / favicon.ico> ,那么应该这样做:
< link rel =shortcut icontype =image / x-iconhref =#{resource ['images / favicon.ico']}/>
另请参阅:
How do I add a favicon to a JSF project and reference it in <link>
element?
I tried as below:
<h:head>
<link rel="icon" type="image/x-icon" href="images/favicon.ico"/>
...
</h:head>
However, it didn't show any favicon.
A relative href
is relative to the current request URI. Likely it resolved to an invalid URL. You need to prepend with the context path so that it becomes relative to the domain root.
Also, the rel
has better to be shortcut icon
to get it to work in older browsers too.
In case of using an .ico
file, you also need to ensure that it's a real .ico
file and not some .bmp
renamed to .ico
. You can generate one here based on several image formats. You can however also just use a .png
or .gif
file.
All in all, provided that the file is located in
WebContent
|-- images
| `-- favicon.ico
:
then this should do it:
<link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/images/favicon.ico"/>
If you've however placed it as a JSF resource in the /resources
folder as follows
WebContent
|-- resources
| `-- images
| `-- favicon.ico
:
which would make it accessible by <h:graphicImage name="images/favicon.ico">
, then this should do it:
<link rel="shortcut icon" type="image/x-icon" href="#{resource['images/favicon.ico']}"/>
See also:
这篇关于将favicon添加到JSF项目并在< link>中引用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!