Method call method under struts2 action

Source: Internet
Author: User

1. Add <constant name = "struts. Enable. dynamicmethodinvocation" value = "true"/> In struts. XML to open the DMI function in struts. The call method is useraction! Add

Solve the Problem of there is no action mapped for namespace [/user] and action name [user! Add] associated with context path error.

 

2. Use wildcards

Use wildcards to add to favorites in the struts2 configuration file
Form 1: Call different methods in the same action
<Action name = "* Action" class = "jcuckoo. loginregistaction "method =" {1} "> <result name =" input ">/login. JSP </result> <result name = "error">/error. JSP </result>
<Result name = "success">/welcome. jsp </result> </Action>
The value of the first * in the Value Name attribute value of the expression {1.
If the requested URL is loginaction. Action, the login method in jcuckoo. loginregistaction is called. If the requested URL is registeraction. Action, the Register Method in jcuckoo. loginregistaction is called;
Form 2: Call the execute method of different actions through matching
 
<Action name = "* Action" class = "jcuckoo. {1} action "> <result name =" input ">/login. JSP </result> <result name = "error">/error. JSP </result>
<Result name = "success">/welcome. jsp </result> </Action>
The method attribute is not shown above, so the corresponding execute method is called by default.
If the requested URL is loginaction. Action, The execute method in jcuckoo. loginaction is called. If the requested URL is registeraction. Action, The execute method in jcuckoo. registeraction is called;
Form 3: dynamic results
<Action name = "crud _ *" class = "jcuckoo. crudaction "method =" {1} "> <result name =" input ">/input. JSP </result> <result>/{1 }. JSP </result> </Action>
When the processing result is input, the/input. jsp page is displayed.


October 2014 licensed physician Qualification Examination comprehensive medical examination clinical licensed physician oral licensed physician TCM licensed physician


When the processing result is success,
If crud_create.action is used, the create method in jcuckoo. crudaction is executed and jumps to/create. jsp. If crud_delete.action is used, the delete method in jcuckoo. crudaction is executed and the method jumps to/Delete. jsp;

Method call method under struts2 action

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.