3

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 ?

1

1 Answer 1

5

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

http://server.com/contextroot/

Best practise would say to create a folder WebContent/css and place your file loginregister.css in there. Your link will then be

<link rel="stylesheet" type="text/css" href="css/loginregister.css" media="screen"> 

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

http://server.com/contextroot/css/loginregister.css

[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.

http://server.com/contextroot/login.html
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.