Spring3 Js/css/jpg/gif and other static resources cannot be found (no mapping found for HTTP request with URI) problem resolution
Source: Internet
Author: User
<span id="Label3"></p><p><p>Recently used in the project to Spring3, in the exclamation Spring3 annotation configuration is refreshing at the same time unexpectedly appeared this discordant thing, really unbearable</p></p><p><p>Issue: A similar warning appears when the program loads or is accessed with a browser after the project is deployed, 2011-01-19 10:52:51,646 WARN [org.springframework.web.servlet.PageNotFound]-<no Mapping found for HTTP request with URI [/sanddemo001/images/1.jpg] in Dispatcherservlet with Name ' spring ', mainly look at the inside of the angle Brackets.</p></p><p><p>Problem Reason: The culprit is the configuration of the Dispatcherservlet request URL mapping for spring under Web. xml, which is configured as Follows:</p></p><p><p><strong><servlet><br><servlet-name>spring</servlet-name><br><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><br><load-on-startup>1</load-on-startup><br></servlet><br><servlet-mapping><br><servlet-name>spring</servlet-name><br><url-pattern>/</url-pattern><br></servlet-mapping></strong></p></p><p><p>Analysis of the cause:<servlet-mapping> <url-pattern>/</url-pattern> put all the requests to spring to deal with, And all available request URLs are configured in Constroller with annotations like @requestmapping (value = "/login/{user}", method = requestmethod.get), In this way, access to static resources such as Js/css/jpg/gif will not be available.</p></p><p><p>Workaround: Add the following configuration in Web. XML</p></p><p><p><strong><servlet-mapping><br><servlet-name>default</servlet-name><br><url-pattern>*.css</url-pattern><br></servlet-mapping><br><br><servlet-mapping><br><servlet-name>default</servlet-name><br><url-pattern>*.gif</url-pattern></strong></p></p><p><p><strong></servlet-mapping><br><br><servlet-mapping><br><servlet-name>default</servlet-name><br><url-pattern>*.jpg</url-pattern><br></servlet-mapping><br><br><servlet-mapping><br><servlet-name>default</servlet-name><br><url-pattern>*.js</url-pattern><br></servlet-mapping><br><br></strong></p></p><p><p><strong><strong>Workaround 2: Add the following line to the spring configuration file:</strong></strong></p></p><p><p><strong><mvc:default-servlet-handler/></strong></p></p><p><p>Note that the required version is spring3.0.5 or higher</p></p><p><p><strong>Workaround 3</strong></p></p><!--Handles HTTP GET requests for/resources/** by efficiently serving up static resources in the ${webapproot}/resour CES directory--<br><br><mvc:resources mapping= "/resources/**" location= "/resources/"/><br><br>This configuration tells spring how static resources are handled<p><p></p></p><p class="postfoot"><p class="postfoot">Reprint: http://www.blogjava.net/Steven-bot/articles/361333.html</p></p><p><p>Spring3 Js/css/jpg/gif and other static resources cannot be found (no mapping found for HTTP request with URI) problem resolution</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service