首页 > 代码库 > Struts清楚session方法

Struts清楚session方法

//第一种方法(继承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.clear();
return super.execute();
}




}
//第三种方法(一样用ActionContext取session,然后取一个Session的KEY,清除该KEY的session,这种办法可以选择性的清理你要清理的session)
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();
}

}

 

 

相关链接【很重要!】http://www.iteye.com/problems/28692

                            http://jackzhangyunjie.iteye.com/blog/231205/

                            http://bbs.csdn.net/topics/340144247

                            

Struts清楚session方法