jsf - 如何从 JSF 的/WEB-INF 文件夹中获取属性文件?

标签 jsf properties managed-bean properties-file web-inf

我在 /WEB-INF 中有一些属性文件.我想将它加载到 JSF 托管 bean 中。有没有办法做到这一点?

最佳答案

使用 ExternalContext#getResource() ExternalContext#getResourceAsStream() 其中你传递了 webcontent-relative 路径。
例如。:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Properties properties = new Properties();
// ...
properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties"));
这在幕后代表ServletContext#getResource()/getResourceAsStream() .
也可以看看:
  • Where to place and how to read configuration resource files in servlet based application?
  • 关于jsf - 如何从 JSF 的/WEB-INF 文件夹中获取属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2139367/

    相关文章:

    jsf - 新手 JSF 问题 - 如何实现这种布局?

    java - Spring Hibernate JSF 集成状态 404

    ios - Objective-C 从字符串中获取类属性

    jquery - jquery中通过构造函数设置类属性

    c# - 如何在 VS2008(自动属性)中使用 "short style"属性设置默认值?

    java - 具有动态属性的对象的添加/编辑操作

    jsf - 识别和解决javax.el.PropertyNotFoundException:目标不可达

    jsf - 可以在不点击 `valueChangeListener` 键的情况下为 `p:inputText` 执行 `enter` 吗?

    java - 数据表不显示值

    java - 带有 Cocoon 的 JSF