In my spark-java project, I put css file and js file into folder static
in src/main/resources
. I use Spark.staticFileLocation("/static")
to set the static file path.
When I use get("/posts", (req, res) ->{...})
, css and js file can load correctly. The path is http://0.0.0.0:4567/css/style.css
, it works well.
But when I want to get the single post by postId get("/post/:postId", (req, res) ->{...})
, it can't load the css and js file correctly. The path become http://0.0.0.0:4567/post/css/style.css
, it can't work.
How to fix such these problem?