wood burning stoves*
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
Author

Cannot load css in Spring

Nusrat Sultana
Greenhorn

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
/src/main/resources/css

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 .

-Nusrat
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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
https://github.com/SpringSource/spring-petclinic/blob/master/src/main/webapp/WEB-INF/web.xml


https://github.com/SpringSource/spring-petclinic/blob/master/src/main/resources/spring/mvc-core-config.xml


https://github.com/SpringSource/spring-petclinic/blob/master/src/main/webapp/WEB-INF/jsp/fragments/headTag.jsp


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

Joined: Aug 24, 2013
Posts: 5
Hi ,
as your project says , I have moved my css folder in src\main\webapp\resources\css
Added
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
<context-root>/resources/css

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

if your css folder is under web-inf like below example
WEB-INF/resources/css

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

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 .

-Nusrat
 
Don't get me started about those stupid light bulbs.
 
subject: Cannot load css in Spring