# 4.3.3 登出

与登录应用程序同样重要的是登出。要启用登出功能，只需调用 HttpSecurity 对象上的 logout：

```java
.and()
    .logout()
        .logoutSuccessUrl("/")
```

这将设置一个安全筛选器来拦截发送到 /logout 的请求。因此，要提供登出功能，只需在应用程序的视图中添加登出表单和按钮：

```markup
<form method="POST" th:action="@{/logout}">
    <input type="submit" value="Logout"/>
</form>
```

当用户单击按钮时，他们的 session 将被清除，他们将退出应用程序。默认情况下，它们将被重定向到登录页面，在那里它们可以再次登录。但是，如果希望它们被发送到另一个页面，可以调用 logoutSucessFilter() 来指定一个不同的登出后的登录页面：

```java
.and()
    .logout()
        .logoutSuccessUrl("/")
```

在这个例子中，用户在登出后将被跳转到主页。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://potoyang.gitbook.io/spring-in-action-v5/di-4-zhang-spring-an-quan/4.3-bao-hu-web-qing-qiu/4.3.3-deng-chu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
