jeudi 6 juin 2019

Does same name html file on different directory has effect on 404 error?

Here's the situation.

I had Index file at templates directory. There was public directory is at same level with templates directory.

Case 1:
I copied index file and pasted it into public directory, which was empty directory. Then added code : static files.location("/public") to main function which is using spark framework. then tried to access to http://localhost:4567/index.html. There was 404 error.

Then I deleted index.html file at templates directory, still 404 error was at http://location:4567/index.html.

Case 2:
However, after deleting index.html at templates directory, I copied the index.html file in public directory and pasted it into templates directory, then 404 error had been gone. ------------ case2

I tried to figure what was going on, but still don't know why. I want to know 2 things.
1) why there was 404 error at case 1?
2) why 404 error was gone at case2?

Can anybody can explain this?

I ran the program by IntelliJ framework.

I expected index.html to be shown but 404 error page was shown.

I ran the program by IntelliJ.

package spark;

import static spark.Spark.*;

public class HelloWorld {
    public static void main(String[] args) {
        staticFiles.location("/public");
        get("/hello", (req, res) -> "Hello World");
    }
}

I expected index.html to be shown, but 404 error page was shown.




Aucun commentaire:

Enregistrer un commentaire