1. We use the most primitive method to search for actions with different annotations.
Configure the struts. xml file first
News/addNewsInfo. jsp
News/editNewsInfo. jsp
News/newsInfo. jsp
The default action is the excute method in NewsInfoAction. Http: // localhost: 8080/test/newsInfoAction.html or http: // localhost: 8080/test/newsInfoAction. action (
)
So there is a question: how can we access other methods in NewsInfoAction?
Access the specified Method
Method 1:
Http: // localhost/struts2/simple/hello! Say. action
You can call the say method in the hello action.
Method 2:
Http: // localhost/struts2/simple/hello. action? Method: say = xxx
You can call the say method. Here, the parameter name is: method: say, which is the most important. struts2 is exactly
The method to be called is determined based on the parameter name, instead of the parameter value. Therefore, the parameter value can be any
Method 3:
There is a method attribute in the action tag of the struts2 configuration file to specify the access to a specific method.
Method 4:
In this way, the action path on the page can be written as hello_say.action, which is the way to access the say method.
2. If struts2 has been handed over to the spring container for management, we can use annotations to find the action and the action method. (This method is recommended. In this way, you do not need to configure various actions in the struts. xml file to lose weight for struts. xml .)
Url: http: // localhost: 8080/test/admin/editproduct.html? ProductInfoId = 1 // The parameter is optional
@ SuppressWarnings ("unchecked ")
@ Action (value = "/admin/editproduct", results = {@ Result (name = "update", location = "product/editProductInfo. jsp ")})
Public String toUpdateProductInfo () throws Exception {
.......
}
The configuration file only requires configuration Annotations:
Cannot be abbreviated