Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

java - I cannot access Robots.txt in Spring-MVC

I am trying to give access to robots.txt in Spring-MVC. To test the code, I put robots.txt in WebContent,Root and WEB-INF but I cannot access to any of them.

I've already applied answers of these questions 1,2,3 to no avail.

MyCode

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" order="0" />
<mvc:annotation-driven />
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This works for me:

Put robots.txt directly under webapp

In mvc-dispatcher-servlet.xml have:

<mvc:default-servlet-handler/>

<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />

Use maven to build your war


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...