views:

26

answers:

1

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 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 ?

+1  A: 

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.

axtavt