是否可以更改h:outputStylesheet和h:outputScript使用的/ resources文件夹名称 [英] Is it possible to change the /resources folder name which is used by h:outputStylesheet and h:outputScript

查看:125
本文介绍了是否可以更改h:outputStylesheet和h:outputScript使用的/ resources文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

h中引用css文件和js文件时,是否有必要提供文件夹名称resources:outputStylesheet h :outputScript

因为当我提供文件夹名称assets而不是resources时,这些文件不会被加载。

Cause when I am giving the folder name "assets" instead of "resources" these files are not loaded.

这就是我使用这些标签的方式:

This is how I am using these tags:

<h:head>
    <h:outputStylesheet name="css/styles.css"/>
    <h:outputScript name="js/site.js"/>
</h:head>

这是我的项目结构:

在截图中你可以看到文件夹名称是资源。然后它正在运作。如何指定其他名称?

In the screenshot you can see the folder name is resources. And then it is working. How can I specify a different name?

推荐答案

文件夹名称根据章节2.6.1.1和2.6.1.2修复 JSF规范

The folder name is fixed as per chapters 2.6.1.1 and 2.6.1.2 of the JSF specification.


2.6.1.1将资源打包到Web应用程序根目录



默认实现必须支持路径下的Web应用程序根
中的打包资源

2.6.1.1 Packaging Resources into the Web Application Root

The default implementation must support packaging resources in the web application root under the path

resources/<resourceIdentifier>

相对于网络应用根。必须使用ExternalContext上的 getResource *()方法访问打包到Web应用程序根目录中的资源。

relative to the web app root. Resources packaged into the web app root must be accessed using the getResource*() methods on ExternalContext.

对于默认实现,类路径中打包的资源必须位于
JAR条目名称下:

For the default implementation, resources packaged in the classpath must reside under the JAR entry name:

META-INF/resources/<resourceIdentifier>

必须使用 getResource *()<来访问打包到类路径中的资源/ code>通过调用当前<$ c的 getContextClassLoader()方法获得的 ClassLoader 的方法$ c>线程

Resources packaged into the classpath must be accessed using the getResource*() methods of the ClassLoader obtained by calling the getContextClassLoader() method of the current Thread.

在两种情况下都提到必须。它没有提到有关更改这些路径的可能配置选项的任何信息。这适用于JSF 2.0和JSF 2.1。

It mentions "must" in both cases. It does not mention anything about a possible configuration option to change those paths. This applies to both JSF 2.0 and JSF 2.1.

然而,在即将到来的JSF 2.2中,它将按照 JSF规范问题996 可以通过新的 javax.faces.WEBAPP_RESOURCES_DIRECTORY 上下文更改路径将相对于webcontent根的路径作为参数值的参数:

In the upcoming JSF 2.2, however, it will as per JSF spec issue 996 be possible to change the path by the new javax.faces.WEBAPP_RESOURCES_DIRECTORY context parameter which takes a path relative to the webcontent root as parameter value:

<context-param>
    <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
    <param-value>WEB-INF/resources</param-value> 
</context-param>

此示例将移动 / resources 文件夹进入 / WEB-INF ,特此确保更高的安全性(即现在不再可以独立于 FacesServlet )。

This example will move the /resources folder into /WEB-INF, hereby ensuring more security (i.e. it is now not possible anymore to access those resources independently from the FacesServlet).

您的特定情况中,您希望在升级到JSF 2.2时使用以下设置:

In your particular case, you'd thus like to use the following setting when having upgraded to JSF 2.2:

<context-param>
    <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
    <param-value>assets</param-value> 
</context-param>

请注意,这仅涵盖第2.6.1.1章中指定的webapp自己的资源,而不是JAR资源。在第2.6.1.2章中规定。 JAR资源的路径仍然应该是 META-INF / resources ,因为这是由Servlet API规范控制的,而不是JSF规范。它是由 ServletContext#getResource() 方法,它不受JSF控制。

Note that this only covers webapp's own resources as specified in chapter 2.6.1.1, not the JAR resources as specified in chapter 2.6.1.2. The path of JAR resources should still be META-INF/resources as this is controlled by Servlet API specification, not the JSF specification. It's namely under the covers obtained by ServletContext#getResource() method which is outside control of JSF.

这篇关于是否可以更改h:outputStylesheet和h:outputScript使用的/ resources文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆