使用
@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;
}
}
request.getSession().removeAttribute(username.nextElement().toString());你试下这个方法
session.removeAttribute就可以清除你指定的session
这个方法我试过,如果存session时就是用这种Servlet API的方式放就去,也就是session.addAtrribute这种方式那么用session.removeAttribute就可以,
但是我现在这情况用session.removeAttribute也不行通过@ModelAttribute("username") String username方式还是会得到这个值