我在/ WEB-INF中有一些属性文件.我想在JSF托管bean中加载它.有没有办法做到这一点?
解决方法
使用
ExternalContext#getResource()
或
ExternalContext#getResourceAsStream()
,其中传递webcontent相对路径.
例如.:
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?