The Convention plug-in implements the Zero Configuration of struts2.1 and later versions

Source: Internet
Author: User

First, let's take a look at Convention. The Convention plug-in is fully working in the background. The default search of the Convention plug-in is the Java class under struts, struts2, action, or actions. The action class must be com. opensymphony. xwork2.action or its name must end with action. Now the Convention plug-in knows to call the corresponding action class for a special request, the next step is to find the jump view, the Convention plug-in will by default search from the WEB-INF/content directory. Although the Convention plug-in knows that the view is there, but does not know how to use the View File, this must be based on the results returned by the action class.

To use this method, First Action inherits the com. opensymphony. xwork2.actionsupport class, and then creates a JSP file in the WEB-INF/content directory with the lowercase letters of the action name. Then use @ action (value = "") to annotate the action class (the annotation knowledge is not described here. ---- When the returned value of the called method is defined in the result, it will return to the path defined in the result, if not defined, it will automatically find the corresponding JSP file in the WEB-INF/content, then return (for example, the action name is loginaction, And the JSP name is loginaction. JSP will automatically search by default ).

Example of an action file:

@ Action (value = "loginaction", Results = {@ result (name = "AAA", location = "/OK. JSP ")}) // @ action is optional. If this parameter is left blank, it is automatically selected. For example, the path name of loginaction should be loginpublic class loginaction extends actionsupport {@ autowiredprivate userdao; private string MSG; Public String execute () {system. out. println ("this is loginaction"); Return "AAA";} Public String getmsg () {return MSG;} public void setmsg (string MSG) {This. MSG = MSG ;}}

Of course, in this code, it is inevitable to find OK. jsp. As mentioned above, if there is no definition, it will automatically find the corresponding one.
In addition, you can also define the path of the action, that is, define the namespace.
When @ namespace ("/test") is annotated with action, the path of the JSP page corresponding to the action should be WEB-INF/content/test/

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.