1 <package name="front" namespace="/front" extends="struts-default"> 2 <default-action-ref name="index" /> 3 <action name="helloword" class="struts.IndexAction"> 4 <result name="add"> 5 /hello.jsp 6 </result> 7 <result name="love"> 8 /love.jsp 9 </result>10 </action>11 </package>
As you can see, the above Program specifies the class = "struts. indexaction" of the action.
Let's take a look at the indexaction class.
1 package struts; 2 Import COM. opensymphony. xwork2.actionsupport; 3 4 5 public class indexaction extends actionsupport {6 Public String add () {7 Return "add"; // return result name 8} 9 Public String love () {10 11 return "love"; 12} 13}
There is no excute () method in it. You can configure it like this.
<Action name = "helloword" class = "struts. indexaction" method = "add">
You can return the value of the add method in the indexaction class,
However, this method is not recommended! The recommended method is dynamic calling, that is, DMI.
For example, in the address bar, enter URL: http: // localhost: 8080/struts2/Front/helloword! Add (! Add is the name of the called method. Execute () is called by default ())
However, if this is entered, an error is returned (there is no action mapped for namespace [/Front] and action name [helloword! Add ()] associated with context path [/struts2_10003].)
Because DMI is not allowed in struts2 by default.
Therefore, you must open <constant name = "struts. Enable. dynamicmethodinvocation" value = "true"/> in the configuration file so that you can enter the address bar dynamically to obtain the expected page.
DMI in struts2 (dynamic method call)