Today, I plan to upload the plug-in function I wrote to Github, create a new Java project, which USES the Spring MVC framework, and then debug the page when I found that I could not find the static resource file, as shown in the figure below:
So I checked the path of the page resource on the JSP at the first time:
<link rel="stylesheet" type="text/css" href="css/amazeui.min.css">
<link rel="stylesheet" type="text/css" href="css/amazeui.cropper.css">
<link rel="stylesheet" type="text/css" href="css/custom_up_img.css">
After confirmation, the path was found to be correct:
Friends can refer to my file path, if the path is wrong, then you can change the path to solve the problem.
Then I go on to my question, which is obviously not a path problem, so what is the reason why the page cannot find the static file?I finally saw the console output the following message:
Interpretation, i.e., when the request distribution, did not find “/ ScreenshotForUpload/CSS/amazeui. Min. CSS” mapping (No mapping found for…) “And I found out what the problem was. It turns out that spring MVC is blocking the request of a page to a static resource, but your controller does not have the mapping of this path, so the page request to a static resource file is not issued correctly. So how do you solve this problem?The following methods are given for reference:
Solutions:
1. Adopt & lt; mvc:default-servlet-handler /> . Add the following sentence to the SPRING MVC XML configuration file: < mvc:default-servlet-handler /> . As shown in the figure below:
After joining, Spring MVC will screen the URL entering the DispatcherServlet, and if a request for static resources is found, the request will be processed by the default Servlet of the Web application server, and if it is not a static resource, then the DispatcherServlet will continue to process. This method is the fastest.
2. Use & lt; mvc:resources /> . You can use < mvc:resources /> , and put the static resources in the Web-inF directory (or wherever you like), then add the following configuration in springMVC-Servlet:
<mvc:resources location="/File floder" mapping="/mapping path"/>
Fill in the path according to the actual situation.
3. In the web.xml file, change the blocking path of Spring MVC to/SpringMVC /* (” SpringMVC “can be replaced with your preferred path), as shown in the figure below
thus distinguishes “requests to Spring MVC” from “requests to static resource files”, but has the disadvantage that all your MVC requests must start with “/ SpringMVC “.
The problem that the static resource file cannot be found caused by Spring MVC can be said to be relatively secret. Novices may be unable to find the root of the problem for a while. I hope this article can provide you with help!
Read More:
- Spring MVC – enable static resource access
- Request cannot get static resource
- The resource has been blocked.
- JavaScript / JS native dynamic introduction of external CSS files and dynamic insertion of CSS code fragments
- How to Fix Spring Boot OTS parsing error: Failed to convert WOFF 2.0
- Mapped Statements collection does not contain value for XXXX
- springboot : Failed to decode downloaded font 和 OTS parsing error
- Why not manage controller in spring container
- Relative path and absolute path${ pageContext.request.contextPath }
- Uncaught syntax error: unexpected token ‘< 0‘
- Invalid use of element UI icon by vite
- An error happened during template parsing (template: “class path resource
- Python custom class typeerror: ‘module’ object is not callable
- [Solved] org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyh.springboot.
- [How to Fix] NameError: name ‘requests‘ is not defined & NameError: name ‘request‘ is not defined
- Failed to load resource: net::ERR_CONNECTION_RESET
- Securityerror: error ᦇ 2148: SWF file (SWF file cannot access local resources)
- 13.2 spring boot start error: whitelabel error page
- Exception of browser accessing servlet404
- Three methods of JavaScript jump to new page