【问题标题】:Retrieving a file from a Tomcat Server on an Apache box从 Apache 机器上的 Tomcat 服务器检索文件
【发布时间】:2014-07-17 20:08:18
【问题描述】:

所以我正在 Tomcat 7 上使用 JSP 开发 Web 应用程序。我需要能够从保存为我计算机上共享文件夹驱动器的几个 Tomcat 服务器中检索日志文件,然后能够使用正则表达式对其进行解析表达。但是,无论如何都可以检索文件而无需使用表单手动上传。

我试过了

public void init() throws ServletException {

        // Define base path somehow. You can define it as init-param of the servlet.
        this.filePath = "/Users/oakesjo/Documents/LogViewerTools";

        // In a Windows environment with the Application server running on the
        // c: volume, the above path is exactly the same as "c:\files".
        // In UNIX, it is just straightforward "/files".
    }

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        // Get requested file by path info.
        String requestedFile = request.getPathInfo();
...}

但是,this.filePath 只会让我访问 C: 驱动器(本地计算机)上的文件,而不是其他网络驱动器。有没有其他方法来配置这个?另外:是否存在仅将文件自动存储到字符串的选项?

【问题讨论】:

    标签: java regex apache jsp tomcat


    【解决方案1】:

    您的小程序可能无权访问日志文件的保存位置。使用 Windows 时,请确保您对尝试访问的文件夹具有完全访问权限。一旦你得到你的文件,你可以通过 bufferedReader 读取它,并使阅读器将所有内容放入一个字符串中。

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 2012-07-17
      • 2018-04-30
      • 2016-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 2014-01-08
      相关资源
      最近更新 更多