How to get properties file from / WEB -INF folder in JSF?

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

+4
source share
3 answers

Use ExternalContext#getResource() or ExternalContext#getResourceAsStream() in which you pass the relative webcontent path.

eg:.

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

This delegates under the covers of ServletContext#getResource() / getResourceAsStream() .

See also:

+13
source

Put it in WEB-INF / classes. This is part of the class path.

+1
source
  String path="/WEB-INF/list.properties"; InputStream is=FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(path); InputStreamReader r = new InputStreamReader(is); BufferedReader br = new BufferedReader(r); 
0
source

Source: https://habr.com/ru/post/1299426/


All Articles