[Struts2 Study Notes] Section 5: Compile struts2 action Code

Source: Internet
Author: User

[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.
 

Related Article

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.