I tried Search the documentation but I still don't understand. Here's my code to start up the app.
public static void main(String[] args){
Javalin app = Javalin.create(
config -> {
config.addStaticFiles("src/main/resources/public", Location.EXTERNAL);
}
);
app.start(9090);
app.get("/", ctx -> {
ctx.redirect("login.html");
});
}
on localhost:9090/login.html, The Login Page Displays The brackets.
{% extends "base.html" %} {% block title %} Login {% endblock %} {% block content %}
{{success}}
Login In
Username
password
{% endblock %}
Overview
In your Javalin route you are perforing a redirect:
Instead of redirecting to a template, you should redirect to a path - and then handle the rendering of the template in that path.
Also, to avoid needing to explicitly configure a Pebble rendering engine (in other words, to use Pebble as the default renderer) you can change your pebble template file suffixes from
.htmlto.peb.(If you use
.htmlthen Javalin will expect you to be using Thymeleaf, not Pebble.)The Template Files
Both of the Pebble template files need to be placed in the standard
resourcesfolder undersrc, with a suitable file extension. As per the documentation:Do not place your templates in the
publicstatic files directory! These template files are not meant to be directly accessible to end users.Both of the Pebble templates are renamed to:
base.peblogin.pebNote the file suffix.
In
login.pebI also changed theextendsdirective to refer to the renamed base template:The Javalin Routes
To handle the redirect you can use the following routes:
The
/route redirects to the/loginroute. That second route handles rendering of thelogin.pebtemplate.This is why you were seeing a raw template in the browser: The redirect was returning the unrendered template file, instead of returning a route.
Also, by using this approach, the URL displayed in the address bar will be correct:
http://localhost:9090/loginUpdate
I forgot to mention a separate point: I recommend you do not use this:
That location is not external to the application and anyway you should not force the deployed application to rely on a
srcdirectory. The more typical approach is this:(Or, use a truly external path, completely outside of your application's location.)