'Spring Boot : How to httpSession.invalidate() after return statement?

I am working on internationalization in Spring boot. Is it possible to httpSession.invalidate() after returning a page.

As an example

        try {
            return "finalPage";
        }finally {
            httpSession.invalidate();
        }

What I am trying to do is to show finalPage.html with selected language option first, after clear the session.

But this example first clears the session and then shows the finalPage.html in English not selected Italian. Which means if I choose Italian language for the firstPage.html I expect finalPage.html also in Italian language not default English.

Is it possible the above code example work the way as I wish?

Note: I have achieved my wish by using Thymeleaf tags, I want to do this on the java side if possible.



Sources

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

Source: Stack Overflow

Solution Source