开发者

spring SimpleUrlHandlerMapping to robots.txt

开发者 https://www.devze.com 2023-01-18 03:25 出处:网络
I am using spring frameworking following is the mapping of url to controller <bean id=\"urlMapping\" class=\"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping\">

I am using spring frameworking following is the mapping of url to controller

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/controller.web">webController</prop>
<prop key="/robots.txt">robotsController</prop>
</props>
</property>
</bean>

When i hit controller.web control gets to the web controller but when i hit robots.txt control do not transfer to the robotsController instead it tries to find out resource robots.txt if i remove robots.txt 开发者_StackOverflow中文版from context dir it says resource not found.

if i change robots.txt to robots.web it works fine it means there is some thing fishy with robots.txt's name any idea ?


I guess your DispatcherServlet is mapped as <url-pattern>*.web</url-pattern>, therefore it handles only requests to *.web.

If you want DispatcherServlet to handle request with different extensions you have several options:

  • Add several url-patterns to <servlet-mapping>:

    <url-pattern>*.web</url-pattern>
    <url-pattern>*.txt</url-pattern>
    
  • Handle all requests with DispatcherServlet mapped as <url-pattern>/</url-pattern>. Note that this approach requires some effort to serve static content, see here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号