{"id":1864,"date":"2011-03-30T12:51:18","date_gmt":"2011-03-30T07:21:18","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1864"},"modified":"2011-03-30T12:51:18","modified_gmt":"2011-03-30T07:21:18","slug":"explain-dynamic-method-invocation-in-struts-2","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/explain-dynamic-method-invocation-in-struts-2\/","title":{"rendered":"Explain dynamic method invocation in Struts 2"},"content":{"rendered":"<p>Dynamic Method invocation is the concept in the Struts action mapping file, where instead of writing &lt;action&gt; for every method, one can map the wild character with the method name having same prefix or suffix.<\/p>\n<p>Example : Instead of writing addOperation, subOperation and divOperation, programmer can write *Operation.<\/p>\n<p>Consider below jsp code:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;s:form action=&quot;calculator_add&quot; &gt;\n&lt;s:textfield name=&quot;num1&quot; label=&quot;Number 1&quot;&gt;&lt;\/s:textfield&gt;\n&lt;s:textfield name=&quot;num2&quot; label=&quot;Number 2&quot;&gt;&lt;\/s:textfield&gt;\n&lt;s:submit action=&quot;calculator_add&quot; value=&quot;Add&quot; \/&gt;\n&lt;s:submit action=&quot;calculator_sub&quot; value=&quot;Substract&quot; \/&gt;\n&lt;\/s:form&gt;\n<\/pre>\n<p><!--more-->Struts configuration:<\/p>\n<pre class=\"brush: xml; highlight: [10,11,12,13]; title: ; notranslate\" title=\"\">\n&lt;package name=&quot;calc&quot; extends=&quot;struts-default&quot;&gt;\n\t\t&lt;action name=&quot;calculatorInput&quot;&gt;\n\t\t\t&lt;result&gt;\/pages\/calculator.jsp&lt;\/result&gt;\n\t\t&lt;\/action&gt;\n\n\t\t&lt;action name=&quot;calculatorResult&quot;&gt;\n\t\t\t&lt;result&gt;\/pages\/calculatorResult.jsp&lt;\/result&gt;\n\t\t&lt;\/action&gt;\n\n\t\t&lt;action name=&quot;calculator_*&quot; method=&quot;{1}&quot;\n\t\t\tclass=&quot;com.G2.Actions.CalculatorAction&quot;&gt;\n\t\t\t&lt;result name=&quot;success&quot; type=&quot;chain&quot;&gt;calculatorResult&lt;\/result&gt;\n\t\t&lt;\/action&gt;\n\n\t&lt;\/package&gt;\n<\/pre>\n<p>As you can see, instead of writing different action, action name is provided like &#8220;calculator_*&#8221;\u009d,  and method=&#8221;\u009d{1}&#8221;\u009d, means if the input is &#8220;calculator_add&#8221;\u009d then the add() method will be executed in Action class. That means we can invoke any methods dynamically other than execute() in action class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explain dynamic method invocation in Struts 2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[16],"tags":[335],"class_list":["post-1864","post","type-post","status-publish","format-standard","hentry","category-struts","tag-struts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1860,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/error-resolved-form-action-defaulting-to-action-attributes-literal-value\/","url_meta":{"origin":1864,"position":0},"title":"Error Resolved- Form action defaulting to &#8216;action&#8217; attribute&#8217;s literal value","author":"Jitendra","date":"March 30, 2011","format":false,"excerpt":"Error Resolved in Struts 2- Form action defaulting to 'action' attribute's literal value","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1851,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/dynamic-results-in-struts-2\/","url_meta":{"origin":1864,"position":1},"title":"Dynamic Results in Struts 2","author":"Jitendra","date":"March 30, 2011","format":false,"excerpt":"Example and sourcecode of creating Dynamic Results in Struts 2","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1834,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/step-by-step-simple-login-application-in-struts-2\/","url_meta":{"origin":1864,"position":2},"title":"Step by Step Simple Login Application in Struts 2","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Example of Simple Login Application in Struts 2","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"Final Structure of Struts 2 login application","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Final-Structure-of-Struts-2-login-application.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1829,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/what-is-struts-2-and-how-it-works\/","url_meta":{"origin":1864,"position":3},"title":"What is Struts 2 and how it works","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"What is Struts 2 and how it works?","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"How Struts 2 Works","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-Struts-2-Works.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2034,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/tutorial-of-simple-jsp-tiles-application-without-struts\/","url_meta":{"origin":1864,"position":4},"title":"Tutorial of Simple JSP Tiles application without Struts","author":"Jitendra","date":"April 15, 2011","format":false,"excerpt":"Example of Simple JSP Tiles application without Struts","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"Simple JSP Tiles without Struts","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/Simple-JSP-Tiles-without-Struts.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1720,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/how-to-create-jsp-custom-tag-using-tag-interface-or-tagsupport\/","url_meta":{"origin":1864,"position":5},"title":"How to Create JSP Custom Tag \u2013 using Tag interface or TagSupport","author":"Jitendra","date":"March 17, 2011","format":false,"excerpt":"Tutorial of creating JSP Custom Tag \u2013 using Tag interface or TagSupport in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"How to Create Custom Tag in JSP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-to-Create-Custom-Tag-in-JSP.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1864"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1864\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}