'How to display the user's nickname in the header

Actually, a more general question is how to display dynamic information loaded from the outside in an embedded page such as header and Footer.

I call a regular page using the controller and send information to this page through the model. And I include the header and footer in it in this way.

<!DOCTYPE html>
<html lang="ru" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>3d_shop</title>
    <link rel="stylesheet" type="text/css" href="/static/css/common/styles.css">
</head>
<body style="margin: 0">
    <div class="page">
        <header th:insert="~{other/fragments :: header}"></header>
 
            <main style="margin-left: 10%; margin-right: 10%;">
            <h2> Welcome! </h2>
            <button>Text</button>
            <div>
                <p>
                    ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                    nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                    nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                    nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                </p>
            </div>
 
            <div class="center_frame"></div>
        </main>
 
        <footer th:insert="~{other/fragments :: footer}" style="margin-top: auto;" ></footer>
    </div>
</body>
</html>

Since the Header is embedded in all pages of the site, it turns out that it somehow has to download the necessary information from the server independently every time any page is loaded if the user is logged in. Since the Header is embedded in all pages of the site, it turns out that it somehow has to download the necessary information from the server independently every time any page is loaded if the user is logged in. Or somehow save it in the context or session so as not to receive it every time from the server. Thank you to all who answered.



Solution 1:[1]

OK, I found the answer to my question and checked that it works. So if anyone needs it here it is:

We upload the information once, in a session or Cookie (I used a session) and then use thymeleaf to get it from any page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Сергей