How to read the files placed in WEB-INF from JSF

Reading files from WEB-INF in JSF

This no different than reading files from a Servlet except it involves a extra step of getting ServletContext from FacesContext

FacesContext context = FacesContext.getCurrentInstance();
ExternalContext externalContext = context.getExternalContext();
ServletContext sc = (ServletContext)externalContext.getContext();
String sc.getRealPath("/WEB-INF/somefile.xml");

Here we are getting the path to the file but you could read it if you like.

Leave a Comment

Your email address will not be published. Required fields are marked *