Java tutorial
/* # # Copyright 2007 The Trustees of Indiana University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # ----------------------------------------------------------------- # # Project: HTRC Sloan job submission web interface # File: LogoutAction.java # Description: # # ----------------------------------------------------------------- # */ package edu.indiana.d2i.sloan.ui; import java.util.Map; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.interceptor.SessionAware; import com.opensymphony.xwork2.ActionSupport; import edu.indiana.d2i.sloan.Constants; /** * Logout action * * @author Guangchen * */ public class LogoutAction extends ActionSupport implements SessionAware, LoginRequired, ServletResponseAware { private static final long serialVersionUID = 1L; private static final Log logger = LogFactory.getLog(LogoutAction.class); private final String webPageTitle = "Home"; private Map<String, Object> session; private HttpServletResponse httpResponse = null; public String execute() throws Exception { String user = (String) session.get(Constants.SESSION_USERNAME); logger.info(user + " log out."); session.clear(); httpResponse.addCookie(new Cookie(Constants.SESSION_EXIST_BEFORE, "false")); return SUCCESS; } @Override public void setSession(Map<String, Object> session) { this.session = session; } @Override public void setServletResponse(HttpServletResponse response) { this.httpResponse = response; } public String getWebPageTitle() { return webPageTitle; } }