CHAPTER 4: Building a Web Application Using Struts 2 179
Listing 4-19 illustrates the form that allows the user to enter a name and submit it.
Listing 4-19. index.jsp
1.
2.
3.
4.
8.
9.
Line 4: When the user submits the form, the action name hello is sent to the
container.
You need a mapping to map the URL to the HelloWorldAction controller. The mapping tells the
Struts 2 framework which class will respond to the user’s action, which method of that class will be
executed, and which view will be rendered as the response. Listing 4-20 illustrates this mapping file.
Listing 4-20. struts.xml
1.<?xml version="1.0" encoding="UTF-8"?>
2.<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
Figure 4-12. The directory structure of the project