问题描述
在Netbeans中,我有一个名为css
的子文件夹,其中有一个名为testcss.css
的文件.
In Netbeans I have a sub folder called css
and a file in it called testcss.css
.
如何从根目录获取Facelets文件以访问testcss.css
文件?
How do I get Facelets file from root to access the testcss.css
file?
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="/testcss.css" title="style" />
我的目录结构是:
Root (not a folder)
css (folder)
testcss.css
此处.. /p>
A screenshot of the structure is available here.
推荐答案
您应将CSS(以及JS和图像)资源放在/resources
文件夹中(如果不存在,则创建一个).
You should put CSS (and JS and image) resources in /resources
folder (create one if it doesn't exist).
Web Pages
|-- META-INF
|-- WEB-INF
|-- resources
| |-- css
| | `-- style.css
| |-- js
| | `-- script.js
| `-- img
| `-- logo.png
|-- index.xhtml
:
完成此操作后,您应该能够使用适当的JSF组件引用CSS(以及JS和图像)资源 <h:outputStylesheet>
(和 <h:outputScript>
和 <h:graphicImage>
)如下:
Once accomplished that, you should be able to reference the CSS (and JS and image) resources using the appropriate JSF components <h:outputStylesheet>
(and <h:outputScript>
and <h:graphicImage>
) as follows:
<h:outputStylesheet name="css/style.css" />
<h:outputScript name="js/script.js" />
<h:graphicImage name="img/logo.png" />
无需摆弄相对路径. JSF将自动生成正确的URL.
No need to fiddle with relative paths. JSF will automagically generate the proper URL.
- How to reference CSS / JS / image resource in Facelets template?
- What is the JSF resource library for and how should it be used?
- Structure for multiple JSF projects with shared code
这篇关于从子文件夹获取.css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!