I am developing an web application in Spring MVC Framework with Eclipse Europa IDE and Tomcat server
My directory structure is(partial):
- WebContent
- WEB-INF
- pages
- CSS
- images
- login.html
- dispatcher-servlet.xml
- web.xml
In my login.html I have a link to a css file as
<link rel="stylesheet" type="text/css" href="CSS/loginregister.css" media="screen">
Since my login.html and CSS folder are in the same folder “pages” I thought this would work.
But NO. The css file didn’t load (login.html appears smoothly)
I also tried:
<href=”/CSS/loginregister.css”>
<href=”pages/CSS/loginregister.css”>
I am accessing the login.html via my controller class.
my URL comes like this: http://localhost:8080/AccountCreation/login.htm
Can any one tell me where is the problem ?
Move your “pages” folder to be under WebContent instead of WEB-INF. JSP pages shold be protected under WEB-INF but not static files like css, js, html.
The root of your application context is WebContent which would be referenced as
Best practise would say to create a folder WebContent/css and place your file loginregister.css in there. Your link will then be
To test, you can simply enter the following URL in your browser to ensure that the css file is being served from your context root as expected
[EDIT]
For your initial testing, also place your login.html in WebContent (e.g.
WebContent/login.html) as well, however you have mentioned you’re using Spring so you’ll probably end up replacing login.html with an equivalent JSP.