「struts2」セッションを削除する方法まとめ
方法1(SessionAwareを継承してsessionを取得、invalidate())
public class ClearAction extends ActionSupport implements SessionAware{
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session22 = request.getSession();
session22.invalidate();
return super.execute();
}
public void setSession(Map arg0) {
}
}
方法2(ActionContextでsessionを取得して、clear())
public class ClearAction extends ActionSupport{
@Override
public String execute() throws Exception {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.clear();
return super.execute();
}
}
方法3
public class ClearAction extends ActionSupport{
@Override
public String execute() throws Exception {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.remove(“bbuser");
session.remove(“gguser");
session.remove(“ffuser");
return super.execute();
}
}