Java Reference
In-Depth Information
Figure 4-12. The directory structure of the project
Listing 4-19 illustrates the form that allows the user to enter a name and submit it.
Listing 4-19. index.jsp
1.<html>
2.<body>
3.
4.<form action="hello">
5.<label for="name">Enter your name</label><br /><input type="text"
6.name="name" /><input type="submit" value="Submit" />
7.</form>
8.</body>
9.</html>
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
3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4. " http://struts.apache.org/dtds/struts-2.0.dtd " >
5.
 
Search WWH ::




Custom Search