-
Notifications
You must be signed in to change notification settings - Fork 2
/
.cheatsheet.xml
103 lines (99 loc) · 5.58 KB
/
.cheatsheet.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<cheatsheet title="CDI + Servlet: Helloworld quickstart">
<intro>
<description>
This quickstart demonstrates the use of CDI 1.0 and Servlet 3.0. It is a simple application that can be used to verify the JBoss EAP server is configured and running correctly.
<br />
<br />
<b>CDI</b>
<br />
<br />
Contexts and Dependency Injection (CDI) defines a set of complementary services that help improve the structure of application code. CDI provides type-safe dependency injection and shrinks the application code base by replace large sections of code with annotations. It also simplifies packaging and deployments and provides lifecycle management
via contexts.
<br />
<br />
<b>Servlet 3.0</b>
<br />
Servlet 3.0 introduces @Servlet, @ServletFilter, @FilterMapping, and other annotations to ease development of servlet applications.
</description>
</intro>
<item skip="false" title="The helloworld example in depth">
<description>
The helloworld application is a simple example that helps you get started with Jakarta EE. This example demonstrates CDI and uses a servlet for the user interface.
<br />
<br />
As usual, let's start by looking at the necessary deployment descriptors.
By now, we're very used to seeing
<b>beans.xml</b>
in
<b>WEB-INF/</b>
, which can be found in the
<b>src/main/webapp</b>
directory of the example.
Notice that we don't need a
<b>web.xml</b>
file.
This example does not contain a JSF file. The user interface is provided by the servlet.
</description>
<command
required="true"
returns="currentProject"
serialization="org.jboss.tools.project.examples.cheatsheet.getProjectForCheatsheet"/>
</item>
<item title="HelloWorldServlet.java">
<description>
Let's take a look at the servlet that handles the request.
</description>
<subitem
label="The @WebServlet annotation provides the URL pattern for this servlet. This annotation replaces the web.xml servlet-mapping entries that were required before Servlet 3.0. "
skip="true">
<command
required="false"
serialization="org.jboss.tools.project.examples.cheatsheet.openFileInEditor(path=/${currentProject}/src/main/java/org/jboss/as/quickstarts/helloworld/HelloWorldServlet.java,fromLine=43,toLine=43)"/>
</subitem>
<subitem label="The HTML page header and footer are defined as static strings. " skip="true">
<command
required="false"
serialization="org.jboss.tools.project.examples.cheatsheet.openFileInEditor(path=/${currentProject}/src/main/java/org/jboss/as/quickstarts/helloworld/HelloWorldServlet.java,fromLine=46,toLine=48)"/>
</subitem>
<subitem
label="The servlet injects the HelloService class using the @Inject annotation. This allows us to easily call the methods in that class."
skip="true">
<command
required="false"
serialization="org.jboss.tools.project.examples.cheatsheet.openFileInEditor(path=/${currentProject}/src/main/java/org/jboss/as/quickstarts/helloworld/HelloWorldServlet.java,fromLine=50,toLine=51)"/>
</subitem>
<subitem
label="The doGet() method processes the HttpServletRequest. It sets the HttpServletResponse content type and gets the PrintWriter that can send text to the client. After writing the header, it calls the HelloService createHelloMessage() method to generate the message that displays on the web page. It then writes the footer and closes the PrintWriter."
skip="true">
<command
required="false"
serialization="org.jboss.tools.project.examples.cheatsheet.openFileInEditor(path=/${currentProject}/src/main/java/org/jboss/as/quickstarts/helloworld/HelloWorldServlet.java,fromLine=53,toLine=61)"/>
</subitem>
</item>
<item title="index.html">
<description>
This HTML page is the default landing page for the application.
</description>
<subitem label="This page does a redirect to the URL that will be handled by the HelloWorldServlet." skip="true">
<command
required="false"
serialization="org.jboss.tools.project.examples.cheatsheet.openFileInEditor(path=/${currentProject}/src/main/webapp/index.html,fromLine=21,toLine=21)"/>
</subitem>
</item>
</cheatsheet>