Jazzhow 2015-12-01 03:48 采纳率: 0%
浏览 7386

spring mvc session 的清除问题

使用
@SessionAttributes({"username"})
@ModelAttribute("username") String username
在session中设置了username属性,不想使用severlet API,只想使用spring mvc的方式
在session中添加session 和删除某一个session
使用sessionStatus.setComplete();会将所有的session全部清掉,但我只想清除一个session,可是session中的username怎么也清不掉,怎么才能清掉username这一个属性?

代码如下:
@Controller
@SessionAttributes({"username"})
public class FristController {

@RequestMapping("index")
public String index(ModelMap model){
    model.put("username","username");
    return "/index.jsp";
}

@ResponseBody
@RequestMapping("clear")
public String clear(ModelMap model){
    model.remove("username");
    return "";
}

@ResponseBody
@RequestMapping("lookSession")
public String look(ModelMap model, @ModelAttribute("username") String username){
    System.out.println(username);
    return username;
}

}

  • 写回答

3条回答

  • 乐古 2015-12-01 04:05
    关注

    request.getSession().removeAttribute(username.nextElement().toString());你试下这个方法

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题