When using struts2 for web development, you need to do the following to complete each function:
First, write a specific method to implement the function in the service, or add a method to an existing service, or write a new service and then add the method.
2. Write an action or add a method to an existing action. If you need to pass the value, define the member variable and define the set or get method.
Third: configure this action in struts. xml. There are two mappings between the request and the Action method, the correspondence between the action execution result and the response interface, and sometimes the interceptor is defined.
4. Compile the interface and use the defined action in the request.
For example, write the logon function:
Use Login
Configure the login --> login method of action. useraction in the configuration file
Write the login method in action, write the userid and password attributes, and provide the set method.
In service...
For example, compile the registration function:
Send the ball in the interface: Register
Configure register --> the Register Method of action. useraction in the configuration file.
Write the Register Method in action, write registration-related attributes, and provide the set method.
In service...
This may be a habit. The request uses the name a, and the method = "A" will be used for configuration, and the action will provide the method. Since this is a habit, why can't we use this habit as a controller choice for the system. Java ee5 uses a large number of default settings. This idea can also be used here.
My suggestions are as follows:
If you like it, you can directly use action. useraction. login on the request interface without configuring struts. xml. Action indicates the package name, useraction supports the class name, and login indicates the method name. If the package name is too long, you can define an alias for the package name in the configuration file.
For the return value of the action method, the original return is a string. Now, you can return a string that represents the logical name, or a specific page file or action. If you need the interceptor, you can use the comments provided by Java 5.
It's just an idea. If there is anything wrong, please correct me.
Li xucheng
Csdn blog
:
Http://blog.csdn.net/javaeeteacher
CsdnStudent base camp:Http://student.csdn.net/invite.php? U= 124362 & C = 7be8ba2b6f3b6cc5