【问题标题】:Host a json file that is outside the war file in tomcat在tomcat中托管一个在war文件之外的json文件
【发布时间】:2016-02-13 00:38:15
【问题描述】:

我有一个 json 文件,它位于 tomcat 的 webapps 文件夹中,但在我的项目文件夹之外。我需要通过 http:localhost:8080/"somePath" 在浏览器上看到这个文件。

我尝试添加以下行:Context docBase="C:/Users/abc/tomcat/webapps" path="/static" /> 到 server.xml 并尝试点击 URL: http:localhost:8080/static/file.json 但我得到 404 not found.

【问题讨论】:

    标签: tomcat web configuration server.xml


    【解决方案1】:

    最好不要在server.xml中定义Context节点:https://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Defining_a_context

    改为创建文件

    $CATALINA_BASE/conf/[enginename]/[hostname]/static.xml
    

    所以在你的情况下,我想是:

    C:/Users/abc/tomcat/conf/Catalina/localhost/static.xml
    

    并在其中放入一个Context 节点:

    <Context path="/static/"
             docBase="C:/Users/abc/tomcat/webapps/static_files/">
    </Context>
    

    这里的 json 文件位于子目录 static_files 中。我不会将整个 webapps 目录暴露给 static 路径。 docBase 甚至不需要在webapps 中,它可以指向文件系统上任何位置的目录。

    重新启动,您的 json 文件将在

    处可用
    http:localhost:8080/static/file.json
    

    【讨论】:

      猜你喜欢
      • 2015-04-18
      • 2017-09-05
      • 2017-11-08
      • 2020-12-03
      • 1970-01-01
      • 2013-01-17
      • 2019-02-12
      • 2010-09-13
      • 2012-07-29
      相关资源
      最近更新 更多