KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > app3 > LogonAction


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 javax.servlet.RequestDispatcher JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpSession JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import org.apache.struts.action.Action;
28 import org.apache.struts.action.ActionError;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33 import org.apache.struts.action.ActionServlet;
34 import org.apache.struts.util.MessageResources;
35
36
37 /**
38  * Implementation of <strong>Action</strong> that validates a user logon.
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 LogonAction extends Action
46 {
47
48
49 // ---------------------------------------------------- Public Methods
50

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

63     public ActionForward execute(ActionMapping mapping,
64                                  ActionForm form,
65                                  HttpServletRequest JavaDoc request,
66                                  HttpServletResponse JavaDoc response)
67                                  throws IOException JavaDoc, ServletException JavaDoc
68     {
69
70       String JavaDoc username = ((LogonForm) form).getUsername();
71       String JavaDoc password = ((LogonForm) form).getPassword();
72
73       // Save our logged-in user in the session,
74
// because we use it again later.
75
HttpSession JavaDoc session = request.getSession();
76       session.setAttribute(Constants.USER_KEY, form);
77
78       // Log this event
79
StringBuffer JavaDoc message = new StringBuffer JavaDoc("LogonAction: User '");
80       message.append(username);
81       message.append("' logged on in session ");
82       message.append(session.getId());
83       servlet.log(message.toString());
84
85       // Forward control to the success URI
86
// specified in struts-config.xml
87
return (mapping.findForward(Constants.CONTINUE));
88
89   }
90
91 }
92
Popular Tags