File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Cannot load css in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Cannot load css in Spring " Watch "Cannot load css in Spring " New topic

Cannot load css in Spring

Nusrat Sultana

Joined: Aug 24, 2013
Posts: 5
I know this has been replied a thousand times already but still i could not manage to load my css in my Spring Project .
I have put my css file in

Following is my user-servlet.xml

I have configured Dispatcher Servlet in my web.xml

I am posting part of my Controller

I have loaded css in my jsp as following,

Please help me figure out where am i doing wrong ?
Some thread post regarding this problem says to put , in user-servlet.xml , But this mapping has some conflicts with my DispatcherServlet in web.xml and makes all my servlet unreachable and gives 404 .

Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

Welcome to the Ranch!

Have a look at the following example from the Spring Pet Clinic. Note you can user curl too you don't need to use spring:url

The web.xml

[How To Ask Questions][Read before you PM me]
Nusrat Sultana

Joined: Aug 24, 2013
Posts: 5
Hi ,
as your project says , I have moved my css folder in src\main\webapp\resources\css
in my user-servlet.xml file
Linked the css using

Now when I open my project in my browser , I can only see a "resources" folder and can not access my other jsp pages .
shai ban
Ranch Hand

Joined: Jan 05, 2010
Posts: 177
Try it.

if your css folder is outside web-inf

then declare like <mvc:resources mapping="/css/**" location="/resources/css/" />

if your css folder is under web-inf like below example

then declare like <mvc:resources mapping="/css/**" location="/WEB-INF/resources/css/" />
Nusrat Sultana

Joined: Aug 24, 2013
Posts: 5
At last it worked after almost 2 days struggling
I want to share my changes if it helps someone else later :

1. I have to add in my user-servlet.xml file

2. Put my css files in src/main/webapp/resources
3. To use css in jsp use

Thanks to everyone .

I agree. Here's the link:
subject: Cannot load css in Spring
It's not a secret anymore!