A way to pass messages from server to HTML is to write them in HTML. HTML is generated by server.
There are other possibilities as well, such as using query params, cookies, ajax calls etc, but if you have no special requirements you should just write the message in the output HTML.
Within the server implementation you could use request attributes, for example. But that's communication within the server application, not between UI and server.
These kind of messages should usually be either a) in response to POST request, where you have redirected to an error page with relevant info in the error page url, making the page cacheable or b) direct response to request parameters in a GET request, so same params would result in same output.