Create Struts action mappings
An action mapping is a configuration file entry that usually contains a reference to an Action class. This entry can contain a reference to a form bean that the action can use, and can also define local forwards and exceptions that are visible only to this action.
Create a Struts enabled Web project or enable an existing Web project with Struts support.
A Struts action is an instance of a subclass of an Action class, which implements a portion of a Web application and whose perform or execute method returns a forward.
An action can perform tasks such as validating a user name and password or performing a computation. For an example of validating a user name and password, see /login in the struts-config.xml Struts configuration file in the struts-example sample application.
An action mapping is a configuration file entry that usually contains a reference to an Action class. This entry can contain a reference to a form bean that the action can use, and can also define local forwards and exceptions that are visible only to this action.
To create a Struts application, configure an action servlet in the deployment descriptor of the application. An action servlet is a servlet that is started by the servlet container of a Web server to process a request that invokes an action. The servlet receives a forward from the action and asks the servlet container to pass the request to the forward URL. An action servlet must be an instance of class...
org.apache.struts.action.ActionServlet
...or of a subclass of that class. An action servlet is the primary component of the controller. A default servlet is automatically added by the Struts tools when you add Struts support to a dynamic Web project.
A Struts action does not always require a form bean reference, depending on how the action is used in JSP files.
To create an action mapping that associates a Struts action with a forward:
- Using the Web diagram editor:
- Drag the Struts Action icon from the Palette onto your Web diagram.
- Type a name for the action and press Enter.
- Using Struts tools:
- In the Enterprise Explorer of the Web perspective, right-click the name of a project or any resource within the project and select
New | Other | Web | Struts | Action Mapping | Next
- On the New Action Mapping page:
- Specify the configuration file name or accept the default.
- Specify the action mapping path or accept the default.
- Optional: Specify the extends action mapping. You can extend a forward or exception by specifying the path of the action that you want to extend.
- If you want to use a form bean, type the form bean name from the Form Bean Name field and select one of the following scopes from the Form Bean Scope drop-down menu:
- request
- session
- Specify the action type. To specify the action type, you can do one of the following:
- Click Browse to select the class.
- Press Ctrl + Space to use content assist to help you select the action type.
- Click Action Type to create the action class specified by the type.
- In the Java package field, specify the name of the Java package in which the class is to be created.
- In the Action class name field, type the name of the new action.
- If you want to specify modifiers that apply to the new class, select one or more of the following check boxes:
- public,
- abstract,
- final
- Verify the value in the Superclass field.
- For each interface that you want to create, click Add and type the name of the interface, the names of matching types, and any qualifiers.
- If you want to create method stubs, select the check boxes of the ones that you want to create.
- Click Finish.