1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.webapp.example2;
24
25
26 import java.io.IOException;
27 import javax.faces.FacesException;
28 import javax.faces.context.FacesContext;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33 /**
34 * <p>Backing bean for the <code>loggedon.jsp</code> page.</p>
35 */
36
37 public class LoggedOn {
38
39
40
41
42
43 private static final Log log = LogFactory.getLog(LoggedOn.class);
44
45
46
47
48
49 /**
50 * <p>Begin the process of logging off.</p>
51 */
52 public String logoff() {
53
54 FacesContext context = FacesContext.getCurrentInstance();
55 if (log.isDebugEnabled()) {
56 log.debug("logoff(" + context + ")");
57 }
58 forward(context, "/logoff.do");
59 return (null);
60
61 }
62
63
64
65
66
67 /**
68 * <p>Forward to the specified URL and mark this response as having
69 * been completed.</p>
70 *
71 * @param context <code>FacesContext</code> for the current request
72 * @param url Context-relative URL to forward to
73 *
74 * @exception FacesException if any error occurs
75 */
76 private void forward(FacesContext context, String url) {
77
78 try {
79 context.getExternalContext().dispatch(url);
80 } catch (IOException e) {
81 throw new FacesException(e);
82 } finally {
83 context.responseComplete();
84 }
85
86 }
87
88
89 }