문제

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?

도움이 되었습니까?

해결책

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

E.g.:

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

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

See also:

다른 팁

Put it in WEB-INF/classes. That is part of the classpath.

     String path="/WEB-INF/list.properties";

    InputStream is=FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(path);
    InputStreamReader r = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(r);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top