Learn Java for Web Development

(Tina Meador) #1

192 CHAPTER 4: Building a Web Application Using Struts 2


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"
4."http://struts.apache.org/dtds/struts-2.3.dtd">
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.<result-type name="tiles"
15.class="org.apache.struts2.views.tiles.TilesResult" />
16.

17.<action name="*Link" method="{1}"
18.class="com.apress.bookstore.action.LinkAction">
19.login
20.allBooks
21.
22.
23.home
24.login
25.

26.
27.logout
28.

29.

30.


   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"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
4.
5.
6.

Free download pdf