问题
In Netbeans I have a sub folder called css
and a file in it called 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" />
My directory structure is:
Root (not a folder)
css (folder)
testcss.css
A screenshot of the structure is available here.
回答1:
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
:
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" />
No need to fiddle with relative paths. JSF will automagically generate the proper URL.
See also:
- 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
回答2:
You need to call the correct path.
for example if your files are organized:
ROOT
CSS(FOLDER)
styles.css
UPLOADED(FOLDER)
index.html
if you are trying to access the styles file from index.html you need to:
href="../css/styles.css"
来源:https://stackoverflow.com/questions/14484985/get-css-file-from-a-sub-folder