# A guestbook with no JavaScript

The finished version of the server-rendered guestbook built up in Part 1 of
the web-development guide. Every interaction is either a GET (load the page)
or a form POST (submit a new message). There is no JavaScript on the client at
all. The browser renders whatever HTML the server sends.

The interesting wrinkle is the POST/Redirect/GET pattern: the POST handler
appends to an in-memory list and then returns a 302 redirect to `/`, instead
of rendering the page directly. The browser follows the redirect, the URL bar
shows `/`, and hitting Reload re-runs the GET without resubmitting the form.

## Layout

```
guestbook/
  Message.java     - record(name, message)
  Server.java      - Javalin: GET /, POST /submit
templates/
  index.jte        - the single page (list + form)
lib/               - all jars on the classpath (Javalin, JTE, Jetty, ...)
Makefile           - compile/run/clean targets
```

The server uses JTE for templating, wired up with the official
`io.javalin:javalin-rendering-jte` adapter. Templates live under `templates/`
and the engine reads them off the filesystem at runtime, so edits hot-reload
without a recompile.

## Run

Requires Java 21. All other dependencies are vendored under `lib/`.

```bash
make run
```

Then visit `http://localhost:8331/`. Stop with Ctrl-C.

`make clean` removes the compiled `.class` files and the JTE precompilation
cache.

## Things to try

- Open DevTools, Network tab, Preserve log on. Submit a message: two entries
  appear, `POST /submit` (status 302) followed by `GET /` (status 200). The
  302's response headers include `Location: /`.
- The URL bar reads `http://localhost:8331/`, not `/submit`. Reload: no
  "resubmit form?" warning.
- View Page Source: every message in the list is right there in the HTML the
  server sent. Nothing is being constructed in the browser.
- Edit `templates/index.jte` while the server runs and reload: JTE picks up
  the change without restarting.
