-1

I have a css file in this directory:

D:\JavaProjects\MyGuessNumber\web\resources\css\bootstrap.css

And in my index.xhtml file I have:

<h:outputStylesheet library="css" name="bootstrap.css" />

When I run this application as:

localhost:8080/MyGuessNumber

the css file loads just fine.

When I use:

http://localhost:8080/MyGuessNumber/faces/index.xhtml

the css is still there.

But when I do:

http://localhost:8080/MyGuessNumber/index.xhtml

the page loads, but no css? How I can I make this work?

Edit: I am using: /faces/*

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

2 Answers2

1

Without /faces/, this URL:

http://localhost:8080/MyGuessNumber/index.xhtml

Will not be processed by:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>

Because you have specify in the web.xml file:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

JSF2 does not generate the HTML from:

<h:outputStylesheet name="css/bootstrap.css" /> 

  Even if you write code in your page index.xhtml, it will not be executed I think.

0

You can make it work by adding below in your index.html,

<link rel="stylesheet" type="text/css" href="/resources/css/bootstrap.css"/>
Avinash Singh
  • 3,421
  • 2
  • 20
  • 21