1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.webapp.example;
24
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpSession;
28 import javax.servlet.http.HttpServletResponse;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36
37 /**
38 * Implementation of <strong>Action</strong> that processes a
39 * user logoff.
40 *
41 * @author Craig R. McClanahan
42 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
43 */
44
45 public final class LogoffAction extends Action {
46
47
48
49
50
51 /**
52 * The <code>Log</code> instance for this application.
53 */
54 private Log log =
55 LogFactory.getLog("org.apache.struts.webapp.Example");
56
57
58
59
60
61 /**
62 * Process the specified HTTP request, and create the corresponding HTTP
63 * response (or forward to another web component that will create it).
64 * Return an <code>ActionForward</code> instance describing where and how
65 * control should be forwarded, or <code>null</code> if the response has
66 * already been completed.
67 *
68 * @param mapping The ActionMapping used to select this instance
69 * @param form The optional ActionForm bean for this request (if any)
70 * @param request The HTTP request we are processing
71 * @param response The HTTP response we are creating
72 *
73 * @exception Exception if business logic throws an exception
74 */
75 public ActionForward execute(ActionMapping mapping,
76 ActionForm form,
77 HttpServletRequest request,
78 HttpServletResponse response)
79 throws Exception {
80
81
82 HttpSession session = request.getSession();
83 User user = (User) session.getAttribute(Constants.USER_KEY);
84
85
86 if (user != null) {
87 if (log.isDebugEnabled()) {
88 log.debug("LogoffAction: User '" + user.getUsername() +
89 "' logged off in session " + session.getId());
90 }
91 } else {
92 if (log.isDebugEnabled()) {
93 log.debug("LogoffActon: User logged off in session " +
94 session.getId());
95 }
96 }
97 session.removeAttribute(Constants.SUBSCRIPTION_KEY);
98 session.removeAttribute(Constants.USER_KEY);
99 session.invalidate();
100
101
102 return (mapping.findForward("success"));
103
104 }
105
106
107 }