1. We use the most primitive method to find the action. different annotations.
Struts.xml files are configured first
<!--Press Info action---
<action name= "newsinfoaction" class= "Com.xxx.NewsInfoAction" >
<result name= "Add" >news/addNewsInfo.jsp</result>
<result name= "Update" >news/editNewsInfo.jsp</result>
<result name= "DataList" >news/newsInfo.jsp</result>
</action>
Action defaults to running the Excute method in Newsinfoaction.
Http://localhost:8080/test/newsInfoAction.html or Http://localhost:8080/test/newsInfoAction.action See how you configure in the Struts.xml file (
<!--change suffix--
<constant name= "struts.action.extension" value= "action,html"/>)
So there is a question, how do we access the other methods in Newsinfoaction?
Access to the specified method
Way One:
Http://localhost/struts2/simple/hello!say.action
Ability to invoke the Say method in the action of Hello
Way two:
Http://localhost/struts2/simple/hello.action?method:say=xxx
Ability to invoke the Say method. Here, the name of the parameter is: Method:say, this is the most basic, struts2 exactly
Depending on the name of the parameter to determine which method to call, not the value of the parameter, so the value of the parameter can be arbitrary
Way three:
A method attribute exists in the action tag of the STRUTS2 configuration file to specify the access specific methods
<action name= "Hello" class= "helloaction" method= "Say" >
Mode four:
<action name= "hello_*" class= "helloaction" method= "{1}" >
This way the action path in the page can be written as hello_say.action is the Say method.
2. Assume that Struts2 has been handed over to the spring container management. We can use annotations to find action and the action's method.
(It is recommended to use this method.) So we don't have to configure all kinds of action in Struts.xml file, can give Struts.xml lose weight.
)
URL: http://localhost:8080/test/admin/editproduct.html?productInfoId=1//Number of parameters is optional
@SuppressWarnings ("Unchecked")
@Action (value = "/admin/editproduct", results = {@Result (name = "Update", location = "product/editproductinfo.jsp")})
Public String Toupdateproductinfo () throws Exception {
。
。
。。。。。
}
Configuration files require only configuration annotations to:
<mvc:annotation-driven/>
<context:annotation-config></context:annotation-config> cannot be shortened into <context:annota Tion-config/>
Struts2 page URL request how to find action