Ask Your Question
1

How can one use Thymeleaf to remove an attribute from session in Spring Boot?

asked 2022-01-30 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-01 18:00:00 +0000

pufferfish gravatar image

To remove an attribute from session using Thymeleaf in Spring Boot, you can use the following code:

  1. In the Controller class:
@GetMapping("/removeSessionAttribute")
public String removeSessionAttribute(HttpSession session) {
    // remove the "someAttribute" from session
    session.removeAttribute("someAttribute");
    return "redirect:/home";
}
  1. In the Thymeleaf template:
<a th:href="@{/removeSessionAttribute}" class="btn btn-primary">Remove Attribute</a>

This code will create a link/button, which will call the removeSessionAttribute() method in the controller to remove the specified attribute from session.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-30 11:00:00 +0000

Seen: 10 times

Last updated: Oct 01 '21