What is DMI? DMI is called a dynamic method call.
The action does not have to execute the Execute method when it is executed, you can use method= to specify which method to perform when you configure the action in the configuration file, or you can dynamically specify in the URL address (the dynamic method calls DMI).
In the first way, add method to the action in Struts.xml:
Copy Code code as follows:
<struts>
<constant name= "Struts.devmode" Value= "true"/>
<span style= "color: #ff6666;" ><package name= "user" extends= "struts-default" namespace= "/user" >
<action name= "Useradd" class= "Com.bjsxt.struts2.user.action.UserAction" method= "Add" >
<result>/user_add_success.jsp</result>
</action>
</span>
<action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" >
<result>/user_add_success.jsp</result>
</action>
</package>
</struts >
The Red font section above is the main way
The second way, DMI, is simple--modifying the URL
Copy Code code as follows:
<% String context = Request.getcontextpath (); %>
<a href= "<%=context%>/user/user!add" > Add user </a>
is to add one after the address "! Followed by the method name, which is similar to a wildcard character.
Either way, you need to add a method (in the Java file)
Copy Code code as follows:
Ackage com.bjsxt.struts2.user.action;
Import Com.opensymphony.xwork2.ActionSupport;
public class Useraction extends Actionsupport {
Public String Add () {
return SUCCESS;
}
}
It returns a string, which is generally used in a second way, because it reduces the number of action.
The above is the STRUTS2 DMI dynamic invocation of the full content of the way, I hope to give you a reference, but also hope that we support the cloud habitat community.