[Struts2 Study Notes] Section 5: Compile struts2 action Code
Bytes --------------------------------------------------------------------------------------
As a matter of fact, I have learned the basic part of struts2, and I personally feel that I can have an intuitive understanding and understanding of the first four articles, so that I can use struts normally in the application. Other struts2 features, you can think about the API for a long time.
Now, let's explain a tutorial on struts2, which can be used as an alternative. It can be used as a reference to guide others in learning struts2.
Writing struts2 code requires only three steps:
1. Map an action to class
The action ing between action and class is configured in struts. xml. The previous configuration is as follows:
/HelloWorld.jsp
The preceding configuration specifies that a hello action corresponds to org. apache. struts. helloworld. action. HelloWorldAction class.
2. Map a result to view
/HelloWorld.jsp
This is to map the success result to the view HelloWorld. jsp.
3. Compile the action processing logic
public String execute() throws Exception { messageStore = new MessageStore() ; helloCount++; return SUCCESS; }
This is a method corresponding to the class and the place where transaction logic is processed. Based on your processing, return the processing result, such as success
In this case, it is necessary to explain the entire process:
First, log on to the interface and accept the user's input tag data input (user name and password)
Then, based on the struts. xml configuration file, find the set method of the corresponding user name and password, and set the input value to the corresponding class object.
Then, the httprequest method is called to obtain the input data (username and password) of the saved object)
Then execute the execute method and return the processing result (such as success)
It is best to display the view to the user (result. jsp) based on the processing result)
This is the entire process of struts2. I feel familiar with this process. It is very easy to add struts2 in my own program.