Record a profound lesson of url mapping

When the blogger was purely handwriting the SpringMVC logic, it was this article: Purely handwriting the SpringMVC logic code , I encountered a long-standing problem. In the process of configuring the handwritten DispatcherServlet, when writing the interception request of addMapping, I used dynamic.addMapping("/*"), When I finally returned to the view, I kept reporting 404. After debugging, I found that the view was also blocked.
It was only later that "/" and "/*" were different.
< url-pattern>/</url-pattern>

It will match path URLs like /login, but will not match suffix URLs with a pattern of *.jsp

< url-pattern>/*</url-pattern>

Will match all URLs: path and suffix URLs (including /login, .jsp, .js and *.html, etc.)

When used, it < url-pattern>/*</url-pattern>will match *.jsp, and when returning to the jsp view, it will enter the Spring DispatcherServlet class again, resulting in the corresponding controller method not being found, so a 404 error is reported

Guess you like

Origin blog.csdn.net/weixin_43911969/article/details/114986386