Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Cannot load css in Spring

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Let me tell you a story about a man named Jed. He made this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic