سؤال

لدي بعض الخصائص في /WEB-INF. وأريد تحميله في الفول المدارة JSF. هل هناك اي طريقة لعمل ذلك؟

هل كانت مفيدة؟

المحلول

استخدام إما ExternalContext#getResource() أو ExternalContext#getResourceAsStream() حيث تقوم بتمرير مسار ويب الترشيح.

على سبيل المثال:

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

هذا المندوبون تحت الأغطية إلى ServletContext#getResource()/getResourceAsStream().

أنظر أيضا:

نصائح أخرى

ضعها في ويب-إنف/فئات. هذا جزء من 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