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

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

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.

Problem reason: The culprit is the configuration of the Dispatcherservlet request URL mapping for spring under Web. XML, which is configured as follows:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

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.

Workaround: Add the following configuration in Web. xml

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>

</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>

That's OK.

Update: The problem has been re-examined today and a solution has been found.

Workaround 2: Add the following line to the spring configuration file:

<mvc:default-servlet-handler/>

Note that the required version is spring3.0.5 or higher

Spring3 Js/css/jpg/gif and other static resources cannot be found (no mapping found for HTTP request with URI) problem resolution

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.