Removing an attribute from the session

It is important to remove values from the session when they are no longer needed. There are two ways in which we can remove values from the session conversational state. The first way is demonstrated in the following snippet. It uses the removeAttribute method available in the WebRequest class:

    @RequestMapping(value="/some-method",method = RequestMethod.GET) 
public String someMethod(/*Other Parameters*/
WebRequest request, SessionStatus status) {
status.setComplete();
request.removeAttribute("exampleSessionAttribute",
WebRequest.SCOPE_SESSION);
//Other Logic
}

This example shows the second approach using the cleanUpAttribute method in SessionAttributeStore:

    @RequestMapping(value = "/some-other-method",  
method = RequestMethod.GET)
public String someOtherMethod(/*Other Parameters*/
SessionAttributeStore store, SessionStatus status) {
status.setComplete();
store.cleanupAttribute(request, "exampleSessionAttribute");
//Other Logic
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset