The next thing we want is the profile to be stored in a session so that it does not get reset every time we go on the profile page. This can apparently prove tiresome to some users and we have to address it.
Tip
HTTP sessions are a way to store information between requests. HTTP is a stateless protocol, which means that there is no way to relate two requests coming from the same user. What most Servlet containers do is they associate a cookie called JSESSIONID
to each user. This cookie will be transmitted in the request header and will allow you to store arbitrary objects in a map, an abstraction called HttpSession
. Such a session will typically end when the user closes or switches web browsers or after a predefined period of inactivity.
We just saw a method to put objects in a session using the @SessionAttributes
annotation. This works well within a controller but makes the data difficult to share when spread across multiple controllers. We have to rely on...