KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example2 > LogoffAction


1 /*
2  * Copyright 1999-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.struts.webapp.example2;
19
20
21 import java.util.Locale JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import javax.servlet.http.HttpSession JavaDoc;
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
33 /**
34  * Implementation of <strong>Action</strong> that processes a
35  * user logoff.
36  *
37  * @author Craig R. McClanahan
38  * @version $Rev: 155886 $ $Date: 2005-03-02 06:04:47 +0000 (Wed, 02 Mar 2005) $
39  */

40
41 public final class LogoffAction extends Action {
42
43
44     // ----------------------------------------------------- Instance Variables
45

46
47     /**
48      * The <code>Log</code> instance for this application.
49      */

50     private Log log =
51         LogFactory.getLog("org.apache.struts.webapp.Example");
52
53
54     // --------------------------------------------------------- Public Methods
55

56
57     /**
58      * Process the specified HTTP request, and create the corresponding HTTP
59      * response (or forward to another web component that will create it).
60      * Return an <code>ActionForward</code> instance describing where and how
61      * control should be forwarded, or <code>null</code> if the response has
62      * already been completed.
63      *
64      * @param mapping The ActionMapping used to select this instance
65      * @param form The optional ActionForm bean for this request (if any)
66      * @param request The HTTP request we are processing
67      * @param response The HTTP response we are creating
68      *
69      * @exception Exception if business logic throws an exception
70      */

71     public ActionForward execute(ActionMapping mapping,
72                  ActionForm form,
73                  HttpServletRequest JavaDoc request,
74                  HttpServletResponse JavaDoc response)
75     throws Exception JavaDoc {
76
77     // Extract attributes we will need
78
Locale JavaDoc locale = getLocale(request);
79     HttpSession JavaDoc session = request.getSession();
80     User user = (User) session.getAttribute(Constants.USER_KEY);
81
82     // Process this user logoff
83
if (user != null) {
84             if (log.isDebugEnabled()) {
85                 log.debug("LogoffAction: User '" + user.getUsername() +
86                           "' logged off in session " + session.getId());
87             }
88     } else {
89             if (log.isDebugEnabled()) {
90                 log.debug("LogoffActon: User logged off in session " +
91                           session.getId());
92             }
93     }
94     session.removeAttribute(Constants.SUBSCRIPTION_KEY);
95     session.removeAttribute(Constants.USER_KEY);
96     session.invalidate();
97
98     // Forward control to the specified success URI
99
return (mapping.findForward("success"));
100
101     }
102
103
104 }
105
Popular Tags