A Sdi A Sdi - 10 months ago 140
Java Question

How to remove the session attributes in spring mvc

I am trying to deploy a Spring mvc application. I have wizard like form which is filled by user and I retain the content of each form in the wizard by utilizing session, until the last page and then user confirms and content is saved. Then the controller redirect to another page. But here I have a form with all previous session attributes, all presented in the form. My question is is there any method to remove all the session attributes from a controller before redirecting to another page
The review page controller:

public String review(@ModelAttribute Resource resource){
// do somthing
return "course_review";

and save course controller

public String save(@ModelAttribute Resource resource) {
// do somthing
return "redirect:/course/add";

and save contoler redirect to
which is controlled by

public String add(Model model) {
//do somthing
return "course_add";

The Controller class is annotated with


Please advise.

Answer Source

Look into this helper class.

From the docs

... attributes will be removed once the handler indicates completion of its conversational session.

public String save(@ModelAttribute Resource resource, SessionStatus status) {