Detailed description of the first program of struts2 (with diagram)

Source: Internet
Author: User

First, we need to write an action in struts2.

<Packagename = "fish" namespace = "/test" extends = "struts-default">

<Actionname = "aa" class = "com. fish. Test" method = "execute">

<Resultname = "success">

/Index. jsp

</Result>

</Action>

</Package>

// First, the package is a package. The name in the action is a custom name, the class is a class name written by yourself, and the method is the method you want to call. Then, use the characters returned in the method to determine the interface to jump.

 

Let's look at the class you want to write in the class.

Packagecom. fish;

 

Public class Test {

Private Stringmessage;

 

Public String getMessage (){

Returnmessage;

}

 

Public String execute () {// This method is the same as above

Message = "My first struts2 ";

Return "success"; // This is the same as the result above.

}

}

 

Next let's take a look at my jsp

In fact, our jsp only has one sentence. We get the message value through the el expression.

$ {Message} // the message is not dependent on the message attribute in the java class, but on the message method. It can be understood that $ (aa) of el is used in getAa ).

 

After these are completed, we will test this class. We will start tomcat and release the project.

Input: http: // 127.0.0.1: 8080/project name/name of the package in struct. Xml (fish)/action

 

In fact, let's take a look

Graph generated by Struct2

 
 

 

We first Associate aa and success with the class we write, and then put the success result into index. jsp through a filter.

 

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.