Use ExternalContext.getResourcePaths("/")
. In a servlet container, this will delegate to ServletContext.getResoucePaths(String)
. As the documentation notes:
For example, for a web application
containing:
/welcome.html
/catalog/index.html
/catalog/products.html
/catalog/offers/books.html
/catalog/offers/music.html
/customer/login.jsp
/WEB-INF/web.xml
/WEB-INF/classes/com.acme.OrderServlet.class
/WEB-INF/lib/catalog.jar!/META-INF/resources/catalog/moreOffers/books.html
getResourcePaths("/")
would return
{"/welcome.html", "/catalog/",
"/customer/", "/WEB-INF/"}
, and
getResourcePaths("/catalog/")
would
return {"/catalog/index.html",
"/catalog/products.html",
"/catalog/offers/",
"/catalog/moreOffers/"}
.
For portable code, do not assume you can access resources via the file system:
This method (getResource(String)
) allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.