get .css file from a sub folder

早过忘川 提交于 2019-12-11 07:27:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!