KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > app3 > LogoffAction


1 /*
2  * Copyright 2003 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 package examples.app3;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.Vector JavaDoc;
23 import javax.servlet.RequestDispatcher JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.action.ActionServlet;
33 import org.apache.struts.util.MessageResources;
34
35
36 /**
37  * Implementation of <strong>Action</strong> that processes a
38  * user logoff.
39  *
40  * @author Craig R. McClanahan
41  * @author Ted Husted
42  * @version $Revision: 1.3 $ $Date: 2004/02/20 12:42:50 $
43  */

44
45 public final class LogoffAction extends Action
46 {
47
48     // ---------------------------------------------------- Public Methods
49

50     /**
51      * Logoff the user.
52      * The event is logged if the debug level is >= Constants.DEBUG.
53      *
54      * @param mapping The ActionMapping used to select this instance
55      * @param actionForm The ActionForm bean for this request (if any)
56      * @param request The HTTP request we are processing
57      * @param response The HTTP response we are creating
58      *
59      * @exception IOException if an input/output error occurs
60      * @exception ServletException if a servlet exception occurs
61      */

62     public ActionForward execute(ActionMapping mapping,
63                                  ActionForm form,
64                                  HttpServletRequest JavaDoc request,
65                                  HttpServletResponse JavaDoc response)
66                                  throws IOException JavaDoc, ServletException JavaDoc
67     {
68
69       // Extract attributes we will need
70
HttpSession JavaDoc session = request.getSession();
71       LogonForm user = (LogonForm)
72         session.getAttribute(Constants.USER_KEY);
73
74       // Log this user logoff
75
if (user != null)
76       {
77         StringBuffer JavaDoc message = new StringBuffer JavaDoc("LogoffAction: User '");
78         message.append(user.getUsername());
79         message.append("' logged off in session ");
80         message.append(session.getId());
81         servlet.log(message.toString());
82       }
83
84       else
85       {
86
87         StringBuffer JavaDoc message = new StringBuffer JavaDoc("LogoffAction: User '");
88         message.append(session.getId());
89         servlet.log(message.toString());
90       }
91
92       // Remove user login; invalidate session
93
session.removeAttribute(Constants.USER_KEY);
94       session.invalidate();
95
96       // Forward control to the specified success URI
97
return (mapping.findForward(Constants.CONTINUE));
98
99     }
100
101 } // End LogoffAction
102
Popular Tags