Spring mvc static file access and spring mvc static access
Spring mvc cannot access static resource files when the following configuration is in the web. xml file:
<! -- Configure springMvcCoreServlet--> <Servlet> <Servlet-name> spring </servlet-name> <Servlet-class> org. springframework. web. servlet. DispatcherServlet </servlet-class> <Init-param> <Param-name> contextConfigLocation </param-name> <! -- Specify springMvcThe path to the configuration file defaults to/WEB-INF/<[Servlet-Name]-servlet. xml> example here is/WEB-INF/spring-servlet.xml The following is the default value --> <Param-value>Classpath*:Config/Spring-servlet.xml </param-value> </Init-param> <! -- Configure Automatic initialization with server startup --> <Load-on-startup> 1 </load-on-startup> </Servlet> <Servlet-mapping> <Servlet-name> spring </servlet-name> <! -Filter all requests --> <Url-pattern>/</url-pattern> </Servlet-mapping> |
You need the following configuration in the spring-servlet.xml file to access the static resource file:
<Mvc: resourceslocation ="/Css /"Mapping ="/Css /**"/> <Mvc: resourceslocation ="/Js /"Mapping ="/Js /**"/> <Mvc: resourceslocation ="/Img /"Mapping ="/Img /**"/> |