本文介绍了如何从JSF的/WEB-INF文件夹中获取属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在/WEB-INF中有一些属性文件.我想将其加载到JSF托管Bean中.有什么办法吗?

I have some properties file in /WEB-INF. And I want to load it in a JSF managed bean. Is there any way to do that?

推荐答案

使用 ExternalContext#getResource() ExternalContext#getResourceAsStream() ,其中您传递了相对于webcontent的路径.

Use either ExternalContext#getResource() or ExternalContext#getResourceAsStream() wherein you pass the webcontent-relative path.

例如:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Properties properties = new Properties();
// ...
properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties"));

这将在幕后授权给ServletContext#getResource()/getResourceAsStream().

这篇关于如何从JSF的/WEB-INF文件夹中获取属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:31