Dynamic Method invocation is the concept in the Struts action mapping file, where instead of writing <action> for every method, one can map the wild character with the method name having same prefix or suffix.
Example : Instead of writing addOperation, subOperation and divOperation, programmer can write *Operation.
Consider below jsp code:
<s:form action="calculator_add" > <s:textfield name="num1" label="Number 1"></s:textfield> <s:textfield name="num2" label="Number 2"></s:textfield> <s:submit action="calculator_add" value="Add" /> <s:submit action="calculator_sub" value="Substract" /> </s:form>
Struts configuration:
<package name="calc" extends="struts-default"> <action name="calculatorInput"> <result>/pages/calculator.jsp</result> </action> <action name="calculatorResult"> <result>/pages/calculatorResult.jsp</result> </action> <action name="calculator_*" method="{1}" class="com.G2.Actions.CalculatorAction"> <result name="success" type="chain">calculatorResult</result> </action> </package>
As you can see, instead of writing different action, action name is provided like “calculator_*”, and method=”{1}”, means if the input is “calculator_add” then the add() method will be executed in Action class. That means we can invoke any methods dynamically other than execute() in action class.
hi i want an custom tag that shows applet whenever request comes on it
Â
it’s a wildcard method selection technique, Dynamic Method Invocation technique uses bang(!) operator
Dynamic Method Invocation technique uses dabang(!) operator not bang(!) . please take care of it.
it is not working
It won’t, instead of try to copy somebody’s code try to get the idea and apply this.
use constants in strus.xml file