Spring MVC@SessionAttribute:如何从会话中删除属性

Spring MVC@SessionAttribute:如何从会话中删除属性,session,spring-mvc,attributes,Session,Spring Mvc,Attributes,我使用@SessionAttribute(“myForm”)在会话中存储myForm。我可以毫无问题地从会话中获取我的表单。但当我试图从会话中删除myForm时,似乎无法使用removeAttribute(“myForm”)删除它 我不确定它出了什么问题。有什么想法吗? 提前感谢。您显示的代码采用相同的方法?是的,在调用removeAttribute()后立即执行检查。 MyForm myForm = (MyForm)request.getSession().removeAttribut

我使用@SessionAttribute(“myForm”)在会话中存储myForm。我可以毫无问题地从会话中获取我的表单。但当我试图从会话中删除myForm时,似乎无法使用removeAttribute(“myForm”)删除它

我不确定它出了什么问题。有什么想法吗?
提前感谢。

您显示的代码采用相同的方法?是的,在调用removeAttribute()后立即执行检查。
    MyForm myForm = (MyForm)request.getSession().removeAttribute("myForm");
    if(myForm != null){
          request.getSession().removeAttribute("myForm"); 
     }
     //get myForm again to check if it has been removed.
     myForm = (MyForm)request.getSession().removeAttribute("myForm");
     //Check it again and the myForm IS NOT NULL after removal.