且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 servlet 访问服务器上的本地文件系统

更新时间:2023-11-29 14:16:52

您可以在打开给定文件时提供完整路径,这样您就可以在 servlet 容器支持的情况下执行此操作(大多数都支持).

You can provide a full path when opening a given file so you can just do that if supported by your servlet container (most do).

请注意,访问底层文件系统使您的应用程序依赖于 servlet 规范无法保证工作的行为,因此它可能不适用于所有 Web 容器 - 例如,服务器分布在两台物理计算机上,任何它可以执行给定的请求,因为在一台物理计算机上有效的文件在另一台物理计算机上可能无效.这可能与您的情况无关,但您需要知道,超出规范会使您的程序供应商依赖.

Note that accessing the underlying file system is making your application dependent on behavior not guaranteed to work by the servlet specification, so it may not work on all web containers - an example could be a server spread over two physical computers, any of which may execute a given request, as a File valid on one physical computer may not be valid on the other. This is probably not relevant in your case, but you need to know that going outside the spec make your program vendor dependent.