This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Cannot load css in Spring

 
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
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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 .
 
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
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic