【问题标题】:absolute path to the resources of the web application(GWT) on the container that hosts it托管它的容器上的 Web 应用程序 (GET) 资源的绝对路径
【发布时间】:2010-08-09 11:43:05
【问题描述】:

我有一个 GWT 应用程序。我正在将它部署在tomcat中。在 servlet 中,我想编写一些代码来创建一个临时文件。现在正在使用 file = new File("./../webapps"+this.getThreadLocalRequest().getContextPath()+"/svg/temp/"+svgName);

但由于“webapps”硬编码的原因,这可能不适用于所有 Web 服务器。请帮助我解决这个问题。

ps: 1) servlet 扩展了 RemoteServiceServlet。 2) "/svg/temp/"+svgName 是我的应用程序特定的。

【问题讨论】:

    标签: java web-applications gwt


    【解决方案1】:

    在 Servlets 2.2 API 之前,临时路径没有标准位置。 2.2 API 将 javax.servlet.context.tmpdir 属性添加到定义在何处写入内容的 servlet 上下文:

    File directory = (File)getServletContext().getAttribute("javax.servlet.context.tmpdir");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-29
      • 2023-03-14
      • 2022-11-04
      • 2021-12-23
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多