Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Intro to Java Web Development with Spark Bells and Whistles Template Reuse and Static Resources

404 message on css files, unable to find file

I had an issue following this video where the webpage wasn't able to find the css file. I kept getting a 404 message, saying it couldn't find the file and wasn't rendering the css I had created.

Well, I figured it out, and I figured I'd put this here for future students:

When creating the "public.css" directory, it is possible that the folder will literally be called "public.css" as opposed to "/public/css", which is what it should be. To fix this problem, create the public directory first, then create the css directory off of that. This will guarantee the compiler recognizes them as separate folders. Then make sure the main.css file is in the css folder. After that, it should work, given the staticFileLocation has been set correctly and the href in the link tag is also pointing to the correct location.

Happy coding! :)

5 Answers

Marking as resolved

This issue still exists in the current version of IntelliJ. Even after you create the "css" directory off of "public" directory, it is still displayed as "public.css" which the IDE recognizes as /public/css as opposed to a CSS file, if done this way. The IDE will display (and concatenate) whatever directory you create after, as long as /public is empty, so if you create /js directory after /public, then, /css after that, it will display as "public.js.css" which the IDE recognizes as /public/js and /public/css.

To avoid this, here's the sequence of how I did, in order:

  1. create the /public folder directory under /public directory
  2. create the "main.css" (or ANY file, the goal is to put something under /public folder)
  3. create the /css folder directory under /public directory
  4. create another New File under /css folder directory called "main.css" [do NOT*** move or drag the "main.css" from Step 2, this will cause the IDE to display /public directory as "public.css" again.]

My directory display was fixed at this point. Although "public.css" seems harmless, it's best to fix it now to avoid the possible conflicts it may create later on.

I don't think 404 relates to css not being found in anyway. If you do the post from the index page - it correctly redirects a user to /sign-in. if you though try to refresh the page by hitting enter, it just does not work since a new get request is being send instead of a post one and we did not include a get handler for /sign-in page.

Daniel Marin
Daniel Marin
8,021 Points

I have InteliJ ultimate when you create the css file in the resuources folder enter in the file name: public/css/app.css It was looking like public.css which threw me off Then I created the js file public/js/app.js And it shows the correct folders no 404 for the both files

So don't try to create folders inside public because it will look like this public.css.js :) If you only want to create the empty folders remember to create them from resources folder with public/css and public/js

Just put: <link rel="stylesheet" href="css/main.css">