2
* Copyright 1999-2001,2004 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.struts.webapp.example2;
21
import java.util.Locale;
22
import javax.servlet.http.HttpServletRequest;
23
import javax.servlet.http.HttpServletResponse;
24
import javax.servlet.http.HttpSession;
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
import org.apache.struts.util.MessageResources;
35
* Implementation of <strong>Action</strong> that processes a
38
* @author Craig R. McClanahan
39
* @version $Revision: 1.3 $ $Date: 2004/04/29 03:58:40 $
42
public final class LogoffAction extends Action {
45
// ----------------------------------------------------- Instance Variables
49
* The <code>Log</code> instance for this application.
52
LogFactory.getLog("org.apache.struts.webapp.Example");
55
// --------------------------------------------------------- Public Methods
59
* Process the specified HTTP request, and create the corresponding HTTP
60
* response (or forward to another web component that will create it).
61
* Return an <code>ActionForward</code> instance describing where and how
62
* control should be forwarded, or <code>null</code> if the response has
63
* already been completed.
65
* @param mapping The ActionMapping used to select this instance
66
* @param actionForm The optional ActionForm bean for this request (if any)
67
* @param request The HTTP request we are processing
68
* @param response The HTTP response we are creating
70
* @exception Exception if business logic throws an exception
72
public ActionForward execute(ActionMapping mapping,
74
HttpServletRequest request,
75
HttpServletResponse response)
78
// Extract attributes we will need
79
Locale locale = getLocale(request);
80
MessageResources messages = getResources(request);
81
HttpSession session = request.getSession();
82
User user = (User) session.getAttribute(Constants.USER_KEY);
84
// Process this user logoff
86
if (log.isDebugEnabled()) {
87
log.debug("LogoffAction: User '" + user.getUsername() +
88
"' logged off in session " + session.getId());
91
if (log.isDebugEnabled()) {
92
log.debug("LogoffActon: User logged off in session " +
96
session.removeAttribute(Constants.SUBSCRIPTION_KEY);
97
session.removeAttribute(Constants.USER_KEY);
100
// Forward control to the specified success URI
101
return (mapping.findForward("success"));