Struts2 's core function is action, and for developers, using STRUTS2 is primarily about writing action, The action class typically implements the Com.opensymphony.xwork2.Action interface and implements the Execute () method in the interface.
The method is as follows:
Public String Execute () throws Exception
STRUTS2 does not require all of the action classes that are written to implement the action interface, or you can write a normal Java class as an action, as long as you implement a public method that returns a non-argument of type string:
Public String xxx ()
In actual development, the action class seldom implements the action interface directly, Usually inherited from the Com.opensymphony.xwork2.ActionSupport class, Actionsupport implements the action interface and some other optional interfaces, provides input validation, error information access, and internationalization support, choosing from Actionsupport Inheritance, you can simplify the definition of an action.
After you have developed the action, you need to configure the action to tell the STRUTS2 framework which action should be taken to handle the request for a URL.
1. Action Mapping:
The action map is the basic "unit of work" in the STRUTS2 framework, where the action map maps a request URL (that is, the name of the action) to an action class, which is used by the framework to determine how to handle a request when a request matches the name of an action.
Full attribute table for action element
Property |
Whether you must |
Description |
Name |
Is |
The name of the action, used to match the URL |
Class |
Whether |
The full class name of the action implementation class |
Method |
Whether |
|