|
In Strust2 the action can define your own way, there are two ways to call a method, one way is struts.xml specified method to indicate the need to use the method, but this method disadvantage is that if there are many ways you Action in the to configure many times, this is very complicated, another method is to use a dynamic method invocation DMI.
To take a simple example -
For example, there LoginAction add, dell method,
1, the configuration file struts.xml
1 < package name = "default" extends = "struts-default">
2 < action name = "login" class = "com.action.loginAction">
3 < result name = "add"> / add.jsp < / result>
4 < result name = "dell"> / dell.jsp < / result>
5 < / action>
6 < / package>
2, the preparation method and add in loginAction the dell methods:
public String add ()
{
return "add";
}
public String dell ()
{
return "dell";
}
3, used in the link! Dynamic call the desired method:
< a href="login!add"> call the add method < /a>
< a href="login!dell"> call dell method < /a>
Common mistakes:
There is no Action mapped for namespace [/ XXX] and action name [xxx! Xxx] associated with context path [/ xxx_method].
Solution:
The default is such Struts.xml
< Constant name = "struts.enable.DynamicMethodInvocation" value = "false" />
We will be wrong in the address bar exclamation dynamic invocation method, we only need to change this sentence to
< ! - Open the Struts DMI ->
< Constant name = "struts.enable.DynamicMethodInvocation" value = "true" /> |
|
|
|