【问题标题】:I cannot access Robots.txt in Spring-MVC我无法在 Spring-MVC 中访问 Robots.txt
【发布时间】:2015-08-31 00:18:40
【问题描述】:

我正在尝试在 Spring-MVC 中授予对 robots.txt 的访问权限。为了测试代码,我将robots.txt 放入WebContentRootWEB-INF,但我无法访问其中任何一个。

我已经应用了这些问题的答案1,2,3 无济于事。

我的代码

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" order="0" />
<mvc:annotation-driven />

【问题讨论】:

  • 放入webapp你有Spring Security设置吗?
  • @NeilMcGuigan 不,我没有那个设置。
  • @NeilMcGuigan 如果我把它放在 webapp 中,如何访问它?我需要在我的 Spring 应用程序或 Tomcat 中配置什么吗?我的根文件夹中有一个 test.jsp 文件,我可以访问但不能访问这个 robots.txt 文件。

标签: java spring spring-mvc web-hosting robots.txt


【解决方案1】:

这对我有用:

robots.txt直接放在webapp下面

mvc-dispatcher-servlet.xml有:

&lt;mvc:default-servlet-handler/&gt;

&lt;mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" /&gt;

使用 maven 构建你的战争

【讨论】:

  • robots.txt 会在 www.domain.com/robots.txt 上提供吗?这是否意味着您将 /resources/** 映射到两个不同的位置? / 和 /Meta-INF/.... ?
  • 您好,如何使用 Java 配置而不是 xml 配置进行配置?谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-01-29
  • 2017-06-12
  • 2018-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多