forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 4
/
struts2.html
executable file
·412 lines (399 loc) · 19.1 KB
/
struts2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>reveal.js - Struts2</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>MVC - Struts 2</h1>
</section>
<section>
<h2>What ?</h2>
<ul>
<li>Created by Craig R. McClanahan</li>
<li>Donated to the Apache software foundation in 2000</li>
<li>Open source framework</li>
<li>Base on Java Servlets and JSP technologies</li>
<li>Action Based Framework</li>
<li>Create web application using MVC 2 architecture</li>
<li>Struts 2 = WebWork + Struts</li>
</ul>
</section>
<section>
<h2>Why ?</h2>
<ul>
<li>Free to develop & deploy - open source</li>
<li>Stable & Mature</li>
<li>Many supported third-party tools</li>
<li>Feature-rich</li>
<li>Flexible & Extendable</li>
<li>Large User Community, Expert Developers and Committers</li>
<li>Easy plug-in</li>
<li>AJAX support</li>
</ul>
</section>
<section>
<h2>Struts 2 framework features</h2>
<ul>
<li>POJO based actions that are easy to test</li>
<li>Action based framework</li>
<li>Model 2 - MVC Implementation</li>
<li>Internationalization(I18N) Support</li>
<li>Rich JSP Tag Libraries</li>
<li>Annotation and XML configuration options</li>
<li>Easy to test and debug</li>
</ul>
</section>
<section>
<h2>MVC - Model</h2>
<ul>
<li>Implement by action class</li>
<li>For model you can use any data access technologies like JDBC, EJB, Hibernate</li>
</ul>
</section>
<section>
<h2>MVC - View</h2>
<ul>
<li>Its your result part. It can be JSP, JSTL, JSF etc.</li>
<li>Presentation part of the MVC</li>
</ul>
</section>
<section>
<h2>MVC - Controller</h2>
<ul>
<li>FilterDispatcher
<ul>
<li>First component that start processing that is why this type of MVC is called front controller MVC</li>
<li>Looks at the request and apply the appropriate action</li>
<li>Struts framework handles all of the controller work</li>
<li>Its configured in web.xml</li>
</ul>
</li>
<li>Interceptors
<ul>
<li>Can execute code before and after an Action is executed</li>
<li>They can be configured per action basis</li>
<li>Can be used for data validation, file upload, double submit guards</li>
</li>
</ul>
</section>
<section>
<h2>Request Lifecycle in Struts 2</h2>
<p><img width="480" height="185" src="img/struts-2-request-cycle.png"></p>
</section>
<section>
<h2>Struts Workflow</h2>
<p><img width="400" height="500" src="img/Struts2-Architecture.png"></p>
</section>
<section>
<h2>Action</h2>
<ul>
<li>Is a basic unit of work</li>
<li>POJO class which has execute method and properties</li>
<li>Action Mapping maps an identifier to action class</li>
<li>Mapping also specifies
<ul>
<li>Set of Result Types</li>
<li>Set of Exception Handlers</li>
<li>An Interceptor Stack</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Result</h2>
<ul>
<li>When an Action class method completes, it return a String
<ul>
<li>THe value of String is used to select a result element</li>
<li>An action mapping will often have a set of results representing different possible outcomes</li>
</ul>
</li>
<li>There are predefined result names (tokens)</li>
<li>Applications can define other result names (tokens) to match specific cases</li>
</ul>
</section>
<section>
<h2>Pre-defined result names (tokens)</h2>
<ul>
<li>String SUCCESS = "success";</li>
<li>String NONE = "none";</li>
<li>String ERROR = "error";</li>
<li>String INPUT = "input";</li>
<li>String LOGIN = "login";</li>
</ul>
</section>
<section data-markdown>
## Action Mapping
<pre><code contenteditable style="margin-top: 20px;">
<action name="Logon" class="tutorial.Logon">
<result type="redirect-action">Menu</result>
<result type="input">/tutorial/Logon.jsp</result>
</action>
</code></pre>
</section>
<section>
<h2>Defining Validation Rules</h2>
<ul>
<li>Per Action class:
<ul>
<li>in a file named <ActionName>-validation.xml</li>
</ul>
</li>
<li>Per Action alias:
<ul>
<li>in a file named <ActionName-alias>-validation.xml</li>
</ul>
</li>
<li>Inheritance hierarchy and interfaces implementd by Action class</li>
</ul>
</section>
<section>
<h2>Bundled Plugins</h2>
<ul>
<li>JSF</li>
<li>REST</li>
<li>Spring</li>
<li>Tiles</li>
<li>JasperReports</li>
<li>JFreeChart</li>
<li>Etc.</li>
</ul>
</section>
<section>
<h2>Components</h2>
<ul>
<li>web.xml
<ul>
<li>Installs a Filter on /*</li>
</ul>
</li>
<li>struts.xml
<ul>
<li>Maps Action names</li>
<li>Defines the navigation flow</li>
</ul>
</li>
<li>Actions
<ul>
<li>Execute a task</li>
</ul>
</li>
<li>Views (JSP or others)
<ul>
<li>Render the UI</li>
</ul>
</li>
</ul>
</section>
<section data-markdown>
## Create web application with Maven
<pre><code contenteditable style="margin-top: 20px;">
mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-webapp \
-DgroupId=com.aug.app \
-DartifactId=augwebapp
</code></pre>
</section>
<section data-markdown>
## Add struts2-core in pom.xml
<pre><code contenteditable style="margin-top: 20px;">
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.16.3</version>
</dependency>
</code></pre>
</section>
<section data-markdown>
## Convert to Eclipse project
<pre><code contenteditable style="margin-top: 20px;">
mvn eclipse:eclipse -Dwtpversion=2.0
</code></pre>
</section>
<section data-markdown>
## Login.jsp
<pre><code contenteditable style="margin-top: 20px;">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
<h1>Augmentis Login</h1>
<s:form action="welcome">
<s:textfield name="username" label="Username" />
<s:password name="password" label="Password" />
<s:submit />
</s:form>
</body>
</html>
</code></pre>
</section>
<section data-markdown>
## welcome.jsp
<pre><code contenteditable style="margin-top: 20px;">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head></head>
<body>
<h1>Augmentis Web Application</h1>
<h4>Welcome <s:property value="username"/> !! </h4>
</body>
</html>
</code></pre>
</section>
<section data-markdown>
## Action class
<pre><code contenteditable style="margin-top: 20px;">
public class WelcomeAction{
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String execute() {
return "success";
}
}
</code></pre>
</section>
<section data-markdown>
## struts.xml
<pre><code contenteditable style="margin-top: 20px;">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login">
<result>pages/login.jsp</result>
</action>
<action name="welcome" class="com.aug.actions.WelcomeAction">
<result name="success">pages/welcome.jsp</result>
</action>
</package>
</struts>
</code></pre>
</section>
<section data-markdown>
## web.xml
<pre><code contenteditable style="margin-top: 20px;">
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Augmentis Web Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
</code></pre>
</section>
<section>
<h2>Struts 2 Annotation</h2>
<ul>
<li>Scanning Methodology - "struts, struts2, action or actions"</li>
<li>Naming Converter</li>
</ul>
</section>
<section data-markdown>
## Scanning Methodology
<pre><code contenteditable style="margin-top: 20px;">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.aug.actions</param-value>
</init-param>
</filter>
</code></pre>
</section>
<section>
<h2>Let's go to Annotation</h2>
<ul>
<li>Add dependency "struts2-convention-plugin" with version "2.3.16.3"</li>
<li>Create a LoginAction extends ActionSupport</li>
<li>Override the execute() in WelcomeAction</li>
</ul>
</section>
<section>
<h2>How to change execute() method name ?</h2>
</section>
<section>
<h2>How to apply struts2 tiles ?</h2>
</section>
<section>
<h1>THE END</h1>
<h3>" ยิ่งให้ ยิ่งได้ ยิ่งเรียนรู้ "</h3>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>