spring SimpleUrlHandlerMapping 到 robots.txt
我正在使用 spring 框架,以下是 url 到控制器的映射
<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>
当我点击controller.web 控件时,它会访问网络控制器,但是当我点击robots.txt 控件时,不会传输到robotsController,而是尝试查找资源robots.txt 如果我从上下文目录中删除 robots.txt 它说找不到资源。
如果我将 robots.txt 更改为 robots.web,它工作正常,这意味着 robots.txt 的名称有些可疑,您知道吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您的
DispatcherServlet
映射为*.web
,因此它仅处理对*.web< 的请求/代码>。
如果您希望 DispatcherServlet 处理具有不同扩展名的请求,您有多种选择:
将多个:
url-pattern
添加到使用
DispatcherServlet 映射为
/
。请注意,此方法需要付出一些努力来提供静态内容,请参阅此处。< /p>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-pattern
s to<servlet-mapping>
:Handle all requests with
DispatcherServlet
mapped as<url-pattern>/</url-pattern>
. Note that this approach requires some effort to serve static content, see here.