Spark static file not displaying

891 views Asked by At

I am currently using spark as a web framework for a project I am working on. It was working correctly and displaying the html page in the public folder but I was having a problem with localhost:4567 not loading the most recent update to the website. I read clearing my cache could fix that reloading problem. After I did that is when I believe I began having this problem. Do not know if this was the cause of this problem but I wanted to make sure everything was known for the problem.

The code I'm having issues with is:

Spark.staticFiles.location("/public"); Spark.get("/",(req, res) -> "index.html");

You can see an example of my issue below: Example Image

2

There are 2 answers

0
Ben Burr On

Are your html files in a "projectName"/resources/templates folder? If not that may be your problem. If you are using an IDE (which it looks like you are) Make sure you label your resources folder. (In IntelliJ, its under File -> project Structure -> Modules) If you need to create a resources/templates folder/ make sure its under the root directory for the project. See here for an example. Note the Resources folder is marked as such.

EDIT: Now that I think about it, is that HTML file supposed to referenced as static? I don't think it is. I think static is supposed to be used for css style sheets and such.

0
SHG On

When you're creating this route:

Spark.get("/",(req, res) -> "index.html");

It will just return the string index.html, and not the file. If you want the file to be returned just delete this route, you don't need it.