1 18 19 package org.apache.struts.webapp.example; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.http.HttpSession ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.struts.action.Action; 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 32 38 public final class LogoffAction extends Action { 39 40 42 45 private Log log = LogFactory.getLog("org.apache.struts.webapp.Example"); 46 47 49 public ActionForward execute( 51 ActionMapping mapping, 52 ActionForm form, 53 HttpServletRequest request, 54 HttpServletResponse response) 55 throws Exception { 56 57 HttpSession session = request.getSession(); 59 User user = (User) session.getAttribute(Constants.USER_KEY); 60 61 if (user != null) { 63 if (log.isDebugEnabled()) { 64 log.debug( 65 "LogoffAction: User '" 66 + user.getUsername() 67 + "' logged off in session " 68 + session.getId()); 69 } 70 } else { 71 if (log.isDebugEnabled()) { 72 log.debug( 73 "LogoffActon: User logged off in session " + session.getId()); 74 } 75 } 76 session.removeAttribute(Constants.SUBSCRIPTION_KEY); 77 session.removeAttribute(Constants.USER_KEY); 78 session.invalidate(); 79 80 return (mapping.findForward("success")); 82 83 } 84 85 } 86 | Popular Tags |