2016-04-29 87 views
0

我最近开始通过名为Zap的工具检查我们的Web应用程序的安全漏洞。运行后,我发现我必须在我们的webapp中包含robots.txt。
该工具正在寻找webapp根目录下的文件(https://localhost:8080),并在那里显示文件,但是它会抛出一个错误,提示“找不到文件”。 我运行的Web服务器是码头-9.3.8及以下为webapp的将robots.txt文件放置在码头服务器上的位置?

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(); 

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

回答

1

你需要一个服务于/contextPath静态内容的东西才能工作。

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

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