seinecle seinecle - 4 months ago 57
Java Question

How to return a static html page with Spark Java?

A hello world with spark:

get(new Route("/hello") {
public Object handle(Request request, Response response) {
return "<h1>Hello Spark MVC Framework!</h1>";

How can I return a static file index.html instead?


  • I need this index.html to be in the jar

  • in the spirit of simplicity of spark java, I'd like to avoid as much as possible going through templates, that would be overkill for a static page.


You can do so by passing the absolute path to your static resources directory in this method:


Or by passing the relative path in this method:


Call this before setting any route. Create your index.html file in the root of your static resources directory.