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.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
user1924104
  • 831
  • 2
  • 15
  • 37
  • You could also try ../testcss.css, I think. – Kyle Yeo Jan 23 '13 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](http://stackoverflow.com/a/1989527) and [this](http://stackoverflow.com/a/3869174) answer). – BalusC Jan 23 '13 at 18:33

2 Answers2

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:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
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"
Eric Goncalves
  • 4,955
  • 4
  • 31
  • 57