DMI in struts2 (dynamic method call)

Source: Internet
Author: User
 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.