淘先锋技术网

首页 1 2 3 4 5 6 7

问题

springmvc添加或者后,静态资源可以访问,Controller不能访问,删掉后才能访问controller

具体配置文件

如果想要解决访问静态资源问题,通常会使用默认handler:

该标签的xsd文档说明如下:

Configures a handler for serving static resources by forwarding to the Servlet container's default Servlet.

Use of this handler allows using a "/" mapping with the DispatcherServlet while still utilizing the Servlet container to serve static resources.

This handler will forward all requests to the default Servlet.

Therefore it is important that it remains last in the order of all other URL HandlerMappings.

That will be the case if you use the "annotation-driven" element

or alternatively if you are setting up your customized HandlerMapping instance

be sure to set its "order" property to a value lower

than that of the DefaultServletHttpRequestHandler, which is Integer.MAX_VALUE.

6799402de3a63d86b9a464db74706e5a.png

default-servlet-handler将在SpringMVC上下文中定义一个DefaultServletHttpRequestHandler。

DefaultServletHttpRequestHandler的javadoc如下:

翻译如下

An {@link HttpRequestHandler} for serving static files using the Servlet container's "default" Servlet.

This handler is intended to be used with a "

The mapping to this handler should generally be ordered as the last in the chain

so that it will only execute when no other more specific mappings (i.e., to controllers) can be matched.

标签:default,servlet,SpringMVC,mapping,访问,handler,DispatcherServlet,Servlet

来源: https://blog.csdn.net/qq_26838315/article/details/112572747