Annotations for earlier versions:
The struts2-core-2.0.11.jar is used to start using annotations
At this time, the filter is org. apache. struts2.dispatcher. FilterDispatcher.
You can specify the action's parent package actionPackages in web. xml.
[Html] <init-param>
<Param-name> actionPackages </param-name>
<Param-value> manning </param-value>
</Init-param>
<Init-param>
<Param-name> actionPackages </param-name>
<Param-value> manning </param-value>
</Init-param>
In the preceding manning package, the class name is TestAction or Test extends ActionSupport.
The content can be blank or empty jump. You only need to add Result (value = "/test. jsp") to the class name, as shown below:
[Java] package manning. chapterTwo;
Import org. apache. struts2.config. Result;
Import org. apache. struts2.dispatcher. ServletDispatcherResult;
Import com. opensymphony. xwork2.ActionSupport;
@ Result (value = "/chapterTwo/AnnotatedNameCollector. jsp ")
Public class AnnotatedNameCollector extends ActionSupport {
}
Package manning. chapterTwo;
Import org. apache. struts2.config. Result;
Import org. apache. struts2.dispatcher. ServletDispatcherResult;
Import com. opensymphony. xwork2.ActionSupport;
@ Result (value = "/chapterTwo/AnnotatedNameCollector. jsp ")
Public class AnnotatedNameCollector extends ActionSupport {
} Or
[Java]
Package manning. chapterTwo;
Import org. apache. struts2.config. Result;
Import org. apache. struts2.dispatcher. ServletDispatcherResult;
@ Result (name = "SUCCESS", value = "/chapterTwo/HelloWorld. jsp ")
Public class AnnotatedHelloWorldAction {
Public String execute (){
Return "SUCCESS ";
}
}
Package manning. chapterTwo;
Import org. apache. struts2.config. Result;
Import org. apache. struts2.dispatcher. ServletDispatcherResult;
@ Result (name = "SUCCESS", value = "/chapterTwo/HelloWorld. jsp ")
Public class AnnotatedHelloWorldAction {
Public String execute (){
Return "SUCCESS ";
}
}
The above part is taken from Struts2InAction.
New Version usage notes:
However, annotations and filters are now updated and later versions use struts2-core-2.3.8.jar
1. strutsPrepareAndExecuteFilter: 2. our implementation annotation also requires struts2-convention-plugin-2.1.8.1.jar3. in struts. xml or struts. properties to set the classes read by the Struts2 framework as Action4. struts. convention. action. packages: indicates the parent package of the Action that can be used. The default value is none. You can read the class marked with @ Action on all headers of this package and its sub-package. struts. convention. package. locators: the upper-level package of the available actions. The default value is [Action, actions, struts, struts2 ], in this way, you can read all the classes registered with @ Action in the header of the package. Note that the set action should be the last level of the package, struts. convention. action. suffix: The suffix of the Action class name. The default value is Action. We will cut down the suffix when using it, for example, TestAction --> access test. action7. @ Result parameter changed to @ Result (name = "SUCCESS", location = "/main. jsp ") name Is success8by default. Multiple Return @ Results ({@ Result (name =" success ", location ="/main. jsp "), @ Result (name =" error ", location ="/error. jsp ")}) 9. you can add a package @ ParentPackage ("struts-default") space @ Namespace ("/test"). The default value is the excute method, and 10 is used to define @ Action on the class name. for other methods, you can define @ Action.
@ Action (value = "add", results = {@ Result (name = "success", location = "/index. jsp ")})
Public String add () throws Exception {
Return SUCCESS;
}