1

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.

2
  • You could also try ../testcss.css, I think. Commented Jan 23, 2013 at 16:57
  • Based on the screenshot and the question history, you're using JSF/Facelets. I've added the appropriate tags to the question. Remember, Facelets is XHTML, but XHTML is not Facelets, so it's absolutely wrong to use the XHTML tag. A lot of users in the XHTML tag are naive and do not understand that it's essentially a template to ease HTML code generation by a XML based tool and incorrectly assumes that XHTML is been used "as-is" (which they incorrectly also do in real world, see also e.g. this and this answer). Commented Jan 23, 2013 at 18:33

2 Answers 2

3

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:

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, have helped a lot ! have now changed all my css etc to the above format
1

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"

4 Comments

Or you could use a root-relative path like /css/testcss.css.
could you write out how your files are organized? or take a screenshot of all the necessary folders expanded and update your question?
Updated, will add a screen grab in a sec
Updated with link to screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.