Some suggestions for improving the Controller in struts2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.