SpringMVC中url-pattern /和/* 的区别

	
		springmvc-servlet
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			classpath:applicationContext.xml
		
		1
	

	
	
		springmvc-servlet
		/
       <-- /*  -->
	

/ 会拦截所有的请求(不包含.jsp)

/* 会拦截所有的请求(包含.jsp)

原因:

在tomcat容器的web.xml中,已经默认配置 /和 *.jsp

如果我们对自己的项目中的web.xml进行配置/,则会使得原本tomcat的配置被覆盖,从而造成我们访问(.html,.js.png)等静态文件出现异常,而jsp页面之所以还能正常访问,则是因为tomcat对.jsp进行了精确配置,

所以我们使用/并不影响我们j对sp页面的访问,所以在日常的springmvc的web.xml配置中,使用/*是十分愚蠢的行为,使用/进行开发的话是为了迎合rest模式开发,所以正常行为下,我们都会配置精确的访问*.action

SpringMVC中url-pattern /和/* 的区别_第1张图片

rest介绍:https://blog.csdn.net/qq_21383435/article/details/80032375

你可能感兴趣的:(springmvc,spring)