Lit*_*ski 4 java sitemap apache tomcat robots.txt
我正在使用Tomcat 7托管我的应用程序。我使用了tomcat-home \ conf \ Catalina \ localhost下的ROOT.xml文件
<Context
docBase="C:\Program Files\Apache Software Foundation\Tomcat 7.0\mywebapp\MyApplication"
path=""
reloadable="true"
/>
Run Code Online (Sandbox Code Playgroud)
这是在根上下文中加载我的webapp。
但是现在我对将robots.txt和sitemap.xml文件放置在何处感到困惑。当我放入C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ mywebapp \ MyApplication下时,它没有显示。
我也尝试将其放在里面C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT,以防万一。但是什么都行不通。我仍然找不到404。任何人都可以指导。
ps我的Web应用程序运行良好。只是我的robots.txt文件无法访问。
我的web.xml文件:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
它应该位于您的上下文目录中
mywebapp\MyApplication
就在你的 web-inf 目录、index.html 等的位置。
更新:
根据我们的讨论,所有 url 均由 Spring MVC DelegatingFilterProxy 处理,因此您需要以某种方式从此过滤器中排除 *.txt,可能是通过扩展 DelegatingFilterProxy 并在 web.xml 中配置该过滤器
解决方案:我可以通过 Spring MVC 中的这个 hack 来服务器静态内容:
<mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/>
Run Code Online (Sandbox Code Playgroud)
帮我解决了很多头痛问题。:) 写它是为了让其他人受益。
| 归档时间: |
|
| 查看次数: |
11365 次 |
| 最近记录: |