Spring not finding resource files (css, jsp...)
The problem is that your requests for CSS and JS files are going through Dispatcher Servlet, which is not correct. Hence Spring won't find the mapping for those files it will not load them.
You need to add the resourceHandler for your application in the applicationContext.xml file as follows. This configuration will bypass the requests for CSS and JS files from the Dispatcher Servlet.
<mvc:resources location="/assets/" mapping="/assets/**" />
Hope this helps you... Cheers.
Please put following code 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>*.js</url-pattern>
</servlet-mapping>
Why CSS from resources is not working in spring jsp page?
You need to put your resources in WebContent
directory and not in src/main/resources
Please move your all static
resources from src/main/resources
to WebContent/resources
directory.
This will allow spring
to scan the static resource properly and then you can rebuild your application.
<!-- the mvc resources tag does the magic -->
<mvc:resources mapping="/resources/**" location="/resources/" />
This will tell DispatcherServlet
to delegate the resource
scanning to correct servlet.
Add css file to resources but can not read it in Spring MVC 3.1
Finally, I changed spring mvc from 3.x to version 4, it worked.
Why can't Spring find resource files?
I finally figured it out by starting over from scratch. The only thing wrong was this line should not have been there in web.xml
<url-pattern>/</url-pattern>
Related Topics
Change Svg Text to CSS Word Wrapping
Jquery: How to Get Assigned Font to Element
Possible to Fade Out Div Border
Does Display:None Keep Elements from Loading
How to Zoom into a Web Page Like Ie or Firefox Do, Using Programming
Safari Bug :First-Child Doesn't Update Display:Block When Items Are Removed with Js
Very Simple JavaScript/Jquery Example: Unexpected Evaluation Order of Instructions
Wrap Text Inside Fixed Div with CSS or JavaScript
Render Closing Tag Conditionally in Order to Emulate Calendar Behavior
Style the Nth Letter in a Span Using CSS
CSS Not Being Applied to Document.Write Text
Sticky Header Flickering on Safari Desktop Only When Anchor Scrolling
Blend Mode:Multiply in Internet Explorer
How to Change the Style of Elements with Same Class Name
CSS Textarea That Expands as You Type Text
How to Change Url in Browser Without Navigating Away from Page