1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package examples.logic;
23
24 import java.util.ArrayList;
25
26 import jakarta.servlet.http.HttpServletRequest;
27 import jakarta.servlet.http.HttpServletResponse;
28
29 import org.apache.struts.action.Action;
30 import org.apache.struts.action.ActionErrors;
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.action.ActionMessage;
35 import org.apache.struts.action.ActionMessages;
36
37 import examples.TestBean;
38 import examples.options.BookBean;
39
40
41
42
43
44
45
46 public class PrepareLogicAction extends Action {
47 private static final long serialVersionUID = 131485024310473177L;
48
49
50
51
52
53
54 public PrepareLogicAction() {
55 super();
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 public ActionForward execute(
75 ActionMapping mapping,
76 ActionForm form,
77 HttpServletRequest request,
78 HttpServletResponse response)
79 throws Exception {
80
81 TestBean bean = new TestBean();
82 request.setAttribute("testBean", bean);
83
84 ArrayList<String> items = new ArrayList<>();
85 request.setAttribute("items", items);
86
87 request.setAttribute("intValue", Integer.valueOf(7));
88 request.setAttribute("stringValue", "Hello, world!");
89
90
91 ArrayList<BookBean> books = new ArrayList<>();
92 books.add(new BookBean("0596003285", "Programming Jakarta Struts"));
93 books.add(new BookBean("1930110502", "Struts in Action"));
94 books.add(new BookBean("1861007817", "Professional Struts Applications"));
95 books.add(new BookBean("0672324725", "Struts Kick Start"));
96 books.add(new BookBean("0471213020", "Mastering Jakarta Struts"));
97 books.add(new BookBean("1558608621", "The Struts Framework"));
98 books.add(new BookBean("0971661901", "Struts Fast Track"));
99 request.setAttribute("books", books);
100
101 ActionErrors errors = new ActionErrors();
102
103 errors.add(ActionMessages.GLOBAL_MESSAGE,
104 new ActionMessage("errors.detail", "This is a global error #1"));
105 errors.add(ActionMessages.GLOBAL_MESSAGE,
106 new ActionMessage("errors.detail", "This is a global error #2"));
107 errors.add("test",
108 new ActionMessage("errors.detail", "This is a test error"));
109
110 ActionMessages messages = new ActionMessages();
111 messages.add(ActionMessages.GLOBAL_MESSAGE,
112 new ActionMessage("message.detail", "This is global message #1"));
113 messages.add(ActionMessages.GLOBAL_MESSAGE,
114 new ActionMessage("message.detail", "This is global message #2"));
115 messages.add("test",
116 new ActionMessage("message.example.simple"));
117
118
119 saveMessages(request, messages);
120 saveErrors(request, errors);
121
122
123 return mapping.findForward("success");
124 }
125 }