[[webflux-ann-sessionattribute]]
= `@SessionAttribute`

[.small]#xref:web/webmvc/mvc-controller/ann-methods/sessionattribute.adoc[See equivalent in the Servlet stack]#

If you need access to pre-existing session attributes that are managed globally
(that is, outside the controller -- for example, by a filter) and may or may not be present,
you can use the `@SessionAttribute` annotation on a method parameter, as the following example shows:

[tabs]
======
Java::
+
[source,java,indent=0,subs="verbatim,quotes"]
----
	@GetMapping("/")
	public String handle(@SessionAttribute User user) { // <1>
		// ...
	}
----
<1> Using `@SessionAttribute`.

Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,quotes"]
----
	@GetMapping("/")
	fun handle(@SessionAttribute user: User): String { // <1>
		// ...
	}
----
<1> Using `@SessionAttribute`.
======

For use cases that require adding or removing session attributes, consider injecting
`WebSession` into the controller method.

For temporary storage of model attributes in the session as part of a controller
workflow, consider using `SessionAttributes`, as described in
xref:web/webflux/controller/ann-methods/sessionattributes.adoc[`@SessionAttributes`].
