KickJava   Java API By Example, From Geeks To Geeks.

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


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

18
19 package org.apache.struts.webapp.example;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import javax.servlet.http.HttpSession JavaDoc;
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 /**
33  * Implementation of <strong>Action</strong> that processes a
34  * user logoff.
35  *
36  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
37  */

38 public final class LogoffAction extends Action {
39
40     // ----------------------------------------------------- Instance Variables
41

42     /**
43      * The <code>Log</code> instance for this application.
44      */

45     private Log log = LogFactory.getLog("org.apache.struts.webapp.Example");
46
47     // --------------------------------------------------------- Public Methods
48

49         // See superclass for Javadoc
50
public ActionForward execute(
51         ActionMapping mapping,
52         ActionForm form,
53         HttpServletRequest JavaDoc request,
54         HttpServletResponse JavaDoc response)
55         throws Exception JavaDoc {
56
57         // Extract attributes we will need
58
HttpSession JavaDoc session = request.getSession();
59         User user = (User) session.getAttribute(Constants.USER_KEY);
60
61         // Process this user logoff
62
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         // Forward control to the specified success URI
81
return (mapping.findForward("success"));
82
83     }
84
85 }
86
Popular Tags