• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot load css in Spring

 
Nusrat Sultana
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nusrat Sultana
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic