【问题标题】:Where to place the robots.txt file on jetty server?将 robots.txt 文件放在码头服务器的什么位置?
【发布时间】:2016-04-29 06:45:17
【问题描述】:

我最近开始通过一个名为 Zap 的工具检查我们的 Web 应用程序的安全漏洞。运行它后,我发现我必须在我们的 webapp 中包含 robots.txt。
该工具正在 webapp (https://localhost:8080) 的根目录中查找该文件,并且该文件出现在那里,但它会抛出一个错误,提示“找不到文件”。 我运行的网络服务器是 Jetty-9.3.8,下面是 webapp 的树形结构

etc 
   - webdefault.xml
webapps
   - myapp
          - web.xml
          - generated-web.xml
robots.txt    

我们使用嵌入式码头来启动服务器。像这样:

    WebAppContext context = new WebAppContext();
    context.setContextPath("/myapp");
    context.setWar(jettyHome + "/webapps/myapp/");
    context.setDefaultsDescriptor(jettyHome + "/etc/webdefault.xml");
    File overrideFile = new File(jettyHome
            + "/webapps/myapp/WEB-INF/generated-web.xml");
    if (overrideFile.exists()) {
        context.setOverrideDescriptor(jettyHome
                + "/webapps/myapp/WEB-INF/generated-web.xml");
    }

    server.setHandler(context);
    server.start();

所以,如何将文件放在根目录中并不是我得到的。 有人对此有任何想法吗?

【问题讨论】:

    标签: jetty robots.txt embedded-jetty


    【解决方案1】:

    您需要从 contextPath/ 提供静态内容的东西才能工作。

    添加另一个 WebAppContextServletContextPathResourceHandler 以提供文件。确保你有 ...

    • context.setContextPath("/")设置
    • context.setBaseResource(Resource.newResource("uri/path/to/my/static/content")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2012-01-08
      • 2016-10-28
      • 1970-01-01
      • 2016-09-16
      • 2018-07-11
      • 2012-11-25
      相关资源
      最近更新 更多