gpt4 book ai didi

java - 从 Web 应用程序遍历部署的文件夹

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:01:46 25 4
gpt4 key购买 nike

Web 应用程序是否可以访问其自己部署的文件夹。我正在使用 JSF 1.2 框架,我需要访问部署目录中的一些文件。

JSF 是否有任何内置方法来为我们提供已部署的文件夹及其中的文件?

最佳答案

使用ExternalContext.getResourcePaths("/") .在 servlet 容器中,这将委托(delegate)给 ServletContext.getResoucePaths(String) .如文档所述:

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/"}
.

对于可移植代码,不要假设您可以通过文件系统访问资源:

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.

关于java - 从 Web 应用程序遍历部署的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5776878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com