从 servlet 访问服务器上的本地文件系统 [英] Accessing local filesystem on the server from a servlet

查看:36
本文介绍了从 servlet 访问服务器上的本地文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的 servlet 访问外部目录(其中包含不同应用程序的一些日志).从我所看到的所有文件路径都是从 servlet 上下文解析的.如何访问 servlet 之外的文件?

I need to access an external directory (which contains some logs of a different application) from my servlet. From what I've seen all the file paths are resolved from the servlet context. How can I access files outside the servlet?

推荐答案

您可以在打开给定文件时提供完整路径,这样您就可以在 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.

这篇关于从 servlet 访问服务器上的本地文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆