Why my css and images can not be read by maven
css, image, maven
Solution
This doesn't sound like a Maven issue to me. I think you may have confused the Spring example resources mapping with the standard Maven resources folder. In this case, your images should be relative to the src/main/webapp folder (i.e. src/main/webapp/resources not src/main/resources). Maven itself doesn't do anything special with src/main/webapp/resources folder.
Update
Just to be clear, the folder "resources" under webapp could be named anything. To reduce any confusion, I've renamed mine to "webstuff". As an example, I have
src/main/webapp/webstuff
src/main/webapp/webstuff/css/base.css
src/main/webapp/webstuff/images/globe.png
Now, in my Spring config, I've changed it to look like this:
<mvc:resources mapping="/webstuff/**" location="/webstuff/" />
The final piece is in how I reference the css & image in my jsp:
<html>
<link rel="stylesheet" href="webstuff/css/default.css" type="text/css">
<body>
<h1>Hello World!</h1>
<img src="webstuff/images/globe.png">
</body>
</html>
Problem
I have a maven project and I want to use a css on the project but it only shows the index.jsp page and no any images and css. What can it depends on? I put my css and images under resources and here is my servlet-context.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <mvc:default-servlet-handler /> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <beans:import resource="controllers.xml" /> </beans:beans> ``` please any help?