如何使用Java来清除session

2024-03-14,

本文小编为大家详细介绍“如何使用Java来清除session”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何使用Java来清除session”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

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

public class ExitAction extends ActionSupport implements SessionAware{
@Overridepublic 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{
@Overridepublic String execute() throws Exception {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.remove("buser");
session.remove("guser");
session.remove("fuser");return super.execute();
}
}

读到这里,这篇“如何使用Java来清除session”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注本站行业资讯频道。

《如何使用Java来清除session.doc》

下载本文的Word格式文档,以方便收藏与打印。