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.