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