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 jakarta.servlet.http.HttpServletRequest;
28 import jakarta.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 private static final long serialVersionUID = -138527557363506974L;
44
45
46
47
48
49
50 public PrepareOptionsAction() {
51 super();
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public ActionForward execute(
71 ActionMapping mapping,
72 ActionForm form,
73 HttpServletRequest request,
74 HttpServletResponse response)
75 throws Exception {
76
77
78 String[] fruits =
79 {
80 "Strawberry",
81 "Apple",
82 "Orange",
83 "Pear",
84 "Mango",
85 "Banana",
86 "Pineapple" };
87 request.setAttribute("fruits", fruits);
88
89
90 String[] colors =
91 { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" };
92 request.setAttribute("colors", colors);
93
94 String[] colorCodes =
95 {
96 "#FF0000",
97 "#FFA500",
98 "#FFFF00",
99 "#00FF00",
100 "#0000FF",
101 "#4B0082",
102 "#EE82EE" };
103 request.setAttribute("colorCodes", colorCodes);
104
105
106 ArrayList<String> colorList = new ArrayList<>();
107 colorList.add("Red");
108 colorList.add("Orange");
109 colorList.add("Yellow");
110 colorList.add("Green");
111 colorList.add("Blue");
112 colorList.add("Indigo");
113 colorList.add("Violet");
114 request.setAttribute("colorCollection", colorList);
115
116
117 ArrayList<LabelValueBean> days = new ArrayList<>();
118 days.add(new LabelValueBean("Monday", "1"));
119 days.add(new LabelValueBean("Tuesday", "2"));
120 days.add(new LabelValueBean("Wednesday", "3"));
121 days.add(new LabelValueBean("Thursday", "4"));
122 days.add(new LabelValueBean("Friday", "5"));
123 days.add(new LabelValueBean("Saturday", "6"));
124 days.add(new LabelValueBean("Sunday", "7"));
125 request.setAttribute("days", days);
126
127
128 ArrayList<BookBean> books = new ArrayList<>();
129 books.add(new BookBean("0596003285", "Programming Jakarta Struts"));
130 books.add(new BookBean("1930110502", "Struts in Action"));
131 books.add(
132 new BookBean("1861007817", "Professional Struts Applications"));
133 books.add(new BookBean("0672324725", "Struts Kick Start"));
134 books.add(new BookBean("0471213020", "Mastering Jakarta Struts"));
135 books.add(new BookBean("1558608621", "The Struts Framework"));
136 books.add(new BookBean("0971661901", "Struts Fast Track"));
137 request.setAttribute("books", books);
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 HashMap<Integer, String> animals = new HashMap<>();
154 animals.put(1, "Cat");
155 animals.put(2, "Dog");
156 animals.put(3, "Horse");
157 animals.put(4, "Rabbit");
158 animals.put(5, "Goldfish");
159 request.setAttribute("animals", animals);
160
161
162 return mapping.findForward("success");
163 }
164 }