KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > app2 > DemoAction


1 /*
2  * Copyright 2003-2004 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.app2;
18
19 import java.io.IOException JavaDoc;
20 import javax.servlet.ServletException JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpSession JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import org.apache.struts.action.Action;
25 import org.apache.struts.action.ActionError;
26 import org.apache.struts.action.ActionErrors;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32
33 /**
34  * <p>A simple action used to demonstrate the view tools.</p>
35  *
36  * @author <a HREF="mailto:sidler@teamup.com"/>Gabe Sidler</a>
37  * @version $Id: DemoAction.java,v 1.4 2004/02/20 12:42:52 marino Exp $
38  */

39 public class DemoAction extends Action
40 {
41
42     /**
43      * Handle server requests.
44      *
45      * @param mapping The ActionMapping used to select this instance
46      * @param actionForm The optional ActionForm bean for this request (if any)
47      * @param request The HTTP request we are processing
48      * @param response The HTTP response we are creating
49      *
50      * @exception IOException if an input/output error occurs
51      * @exception ServletException if a servlet exception occurs
52      */

53     public ActionForward execute(ActionMapping mapping,
54                                  ActionForm form,
55                                  HttpServletRequest JavaDoc request,
56                                  HttpServletResponse JavaDoc response)
57                                  throws IOException JavaDoc, ServletException JavaDoc
58     {
59         String JavaDoc action;
60         HttpSession JavaDoc session;
61
62         // Create serveral error messages to demontrate the output in a template
63
ActionErrors errors = new ActionErrors();
64
65         // Add some global errors
66
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error01"));
67         errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error02"));
68
69         // Add some specific errors
70
errors.add("language", new ActionMessage("error10"));
71         errors.add("language", new ActionMessage("error11"));
72
73         // Save error messages to request attributes
74
saveErrors(request, errors);
75
76
77         // Create serveral error messages to demontrate the output in a template
78
ActionMessages messages = new ActionMessages();
79
80         // Add some global messages
81
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message01"));
82         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message02"));
83
84         // Add some specific messages
85
messages.add("foobar", new ActionMessage("message10"));
86         messages.add("foobar", new ActionMessage("message11"));
87
88         // Save messages to request attributes
89
saveMessages(request, messages);
90
91
92         // Create and save a new transaction token
93
saveToken(request);
94
95         return (mapping.findForward("home"));
96
97     }
98 }
99
100
Popular Tags