Java Reference
In-Depth Information
Listing 4-34 illustrates the
struts.xml
file.
Listing 4-34. struts.xml
1.<?xml version="1.0" encoding="UTF-8" ?>
2.<!DOCTYPE struts PUBLIC
3."-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
5.
6.
7.<struts>
8.<constant name="struts.enable.DynamicMethodInvocation" value="false" />
9.<constant name="struts.devMode" value="true" />
10.<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
11.
12.<package name="default" extends="struts-default" namespace="/">
13.<result-types>
14.<result-type name="tiles"
15.class="org.apache.struts2.views.tiles.TilesResult" />
16.</result-types>
17.<action name="*Link" method="{1}"
18.class="com.apress.bookstore.action.LinkAction">
19.<result name="login" type="tiles">login</result>
20.<result name="allBooks" type="tiles">allBooks</result>
21.</action>
22.<action name="login" class="com.apress.bookstore.action.LoginAction">
23.<result name="success" type="tiles">home</result>
24.<result name="error" type="tiles">login</result>
25.</action>
26.<action name="logout">
27.<result name="success" type="tiles">logout</result>
28.</action>
29.</package>
30.</struts>
Lines 19, 20, 23, 24, and 27
: These lines define the result type as Tiles and the
tile name, such as
home
and
login
, which is defined in
tiles.xml
. Depending
on the result string returned by the action, in other words,
success
or
error
, the
corresponding JSP file defined in
tiles.xml
is mapped with the definition name
in
tiles.xml
to the tile name in
struts.xml
.
Listing 4-35 illustrates the tiles.xml file.
Listing 4-35. tiles.xml
1.<?xml version="1.0" encoding="UTF-8" ?>
2.
3.<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
4.
5.<tiles-definitions>
6.