专注Java教育14年 全国咨询/投诉热线:444-1124-454
赢咖4LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 使用Java来清除session的两种方法

使用Java来清除session的两种方法

更新时间:2022-01-25 11:26:09 来源:赢咖4 浏览3680次

第一种方法(继承SessionAware类来取得session,然后用invalidate()方法清理)

public class ExitAction extends ActionSupport implements SessionAware{
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session1 = request.getSession();
session1.invalidate();
return super.execute();
}
public void setSession(Map arg0) {
}
}

//第二种方法(用ActionContext取session,然后用clear()方法清理)

public class ExitAction extends ActionSupport{
@Override
public String execute() throws Exception {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.remove("buser");
session.remove("guser");
session.remove("fuser");
return super.execute();
}
}

 

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>