您根本不必担心所有 CSS/JS/图像资源中的域名或上下文路径。
代替
<link rel="stylesheet" href="//domain.com/context/resources/style/some.css" />
<script src="//domain.com/context/resources/script/some.js"></script>
<img src="//domain.com/context/resources/images/some.png" />
甚至
<link rel="stylesheet" href="#{request.contextPath}/resources/style/some.css" />
<script src="#{request.contextPath}/resources/script/some.js"></script>
<img src="#{request.contextPath}/resources/images/some.png" />
甚至像其他答案所建议的那样笨拙地更长
<link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/resources/style/some.css" />
<script src="#{facesContext.externalContext.requestContextPath}/resources/script/some.js"></script>
<img src="#{facesContext.externalContext.requestContextPath}/resources/images/some.png" />
你实际上应该使用
<h:outputStylesheet name="style/some.css" />
<h:outputScript name="script/some.js" />
<h:graphicImage name="images/some.png" />
而且,对于 CSS 背景图像,而不是
.some {
background-image: url("../images/some.png");
}
你实际上应该使用
.some {
background-image: url("#{resource['images/some.png']}");
}
也可以看看: