SPRINGMVC deployment Project static resource file access issues

Source: Internet
Author: User

Issue: A similar warning occurs when a program is loaded or accessed using a SPRINGMVC deployment project, 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 inner part 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 Reason:

<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:

Scenario One: Activate Tomcat's defaultservlet to handle static files 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>

To configure multiple, each file configuration one to write in front of the Dispatcherservlet, let Defaultservlet first intercept, this will not enter spring, I think performance is the best.
Tomcat, Jetty, JBoss, and GlassFish the name of the default servlet-the name of the default servlet for the "default" Google App Engine-the "_ah_default" Resin default Ser Vlet's name--"Resin-file" WebLogic default servlet name--"Fileservlet" WebSphere default servlet name--"Simplefileservlet"


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


Workaround 3

<mvc:resources mapping= "/images/**" location= "/images/" cache-period= "31556926"/><mvc:resources mapping= " /js/** "location="/js/"cache-period=" 31556926 "/> <mvc:resources mapping="/css/** "location="/css/" cache-period= "31556926"/>

This configuration tells spring how static resources are handled

Other Links: http://bbs.landingbj.com/t-0-296791-1.html

SPRINGMVC deployment Project static resource file access issues

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.