1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package examples.options;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.util.LabelValueBean;
35
36
37
38
39
40
41
42 public class PrepareOptionsAction extends Action {
43
44
45
46
47
48
49 public PrepareOptionsAction() {
50 super();
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public ActionForward execute(
70 ActionMapping mapping,
71 ActionForm form,
72 HttpServletRequest request,
73 HttpServletResponse response)
74 throws Exception {
75
76
77 String[] fruits =
78 {
79 "Strawberry",
80 "Apple",
81 "Orange",
82 "Pear",
83 "Mango",
84 "Banana",
85 "Pineapple" };
86 request.setAttribute("fruits", fruits);
87
88
89 String[] colors =
90 { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" };
91 request.setAttribute("colors", colors);
92
93 String[] colorCodes =
94 {
95 "#FF0000",
96 "#FFA500",
97 "#FFFF00",
98 "#00FF00",
99 "#0000FF",
100 "#4B0082",
101 "#EE82EE" };
102 request.setAttribute("colorCodes", colorCodes);
103
104
105 ArrayList colorList = new ArrayList();
106 colorList.add("Red");
107 colorList.add("Orange");
108 colorList.add("Yellow");
109 colorList.add("Green");
110 colorList.add("Blue");
111 colorList.add("Indigo");
112 colorList.add("Violet");
113 request.setAttribute("colorCollection", colorList);
114
115
116 ArrayList days = new ArrayList();
117 days.add(new LabelValueBean("Monday", "1"));
118 days.add(new LabelValueBean("Tuesday", "2"));
119 days.add(new LabelValueBean("Wednesday", "3"));
120 days.add(new LabelValueBean("Thursday", "4"));
121 days.add(new LabelValueBean("Friday", "5"));
122 days.add(new LabelValueBean("Saturday", "6"));
123 days.add(new LabelValueBean("Sunday", "7"));
124 request.setAttribute("days", days);
125
126
127 ArrayList books = new ArrayList();
128 books.add(new BookBean("0596003285", "Programming Jakarta Struts"));
129 books.add(new BookBean("1930110502", "Struts in Action"));
130 books.add(
131 new BookBean("1861007817", "Professional Struts Applications"));
132 books.add(new BookBean("0672324725", "Struts Kick Start"));
133 books.add(new BookBean("0471213020", "Mastering Jakarta Struts"));
134 books.add(new BookBean("1558608621", "The Struts Framework"));
135 books.add(new BookBean("0971661901", "Struts Fast Track"));
136 request.setAttribute("books", books);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 HashMap animals = new HashMap();
153 animals.put(new Integer(1), "Cat");
154 animals.put(new Integer(2), "Dog");
155 animals.put(new Integer(3), "Horse");
156 animals.put(new Integer(4), "Rabbit");
157 animals.put(new Integer(5), "Goldfish");
158 request.setAttribute("animals", animals);
159
160
161 return mapping.findForward("success");
162
163 }
164
165 }