Required packages:
- Struts2-config-browser-plugin-2.3.15.2.jar
- Struts2-convention-plugin-2.3.15.2.jar
Note that after adding these two jar packages, you must replace the relevant struts jar packages with the corresponding versions, and use xwork-core as the corresponding versions. Otherwise, errors may occur.
The Struts. xml configuration is as follows:
<! -- Set the path of the ing page -->
<Constant name = "struts. Convention. Result. Path" value = "/WEB-INF/jsp"/>
<! -- Set a keyword for the scan action class -->
<Constant name = "struts. Convention. Package. locators" value = "action"/>
<! -- Set the name separator for the ing page -->
<Constant name = "struts. Convention. Action. Name. separator" value = "-"/>
1. Role of Struts. Convention. Result. Path:
Specifies the path of the response page when the page accesses the action
2. Role of Struts. Convention. Package. locators:
Scan the ** action under those packages as long as the package name contains the specified field.
3. Role of Struts. Convention. Action. Name. separator:
Specifies the part of the character used to cut the action class to remove the suffix of the action to form a Page name mapped to the class, such:
Usertestaction --> usertest --> user-test.jsp
It is separated by uppercase letters and converts uppercase letters to lowercase letters.
Determine the space name:
It is composed of the characters specified by struts. Convention. Package. locators. if:
<Constant name = "struts. Convention. Package. locators" value = "action"/>
For com. lzj. www. Action, its space is named "/",
For com. lzj. www. Action. Test, its space is named "/test"
Determine the Resource Name (that is, the action to be accessed)
It is composed of action class names that remove the suffix of action. Here, the resource name is actually the result after being processed by struts. Convention. Action. Name. separator. if:
Useraction, whose resource name is "user"
Teststrutsaction, whose resource name is: "Test-struts"
Access Method: (assume the project name is strutstest)
If the package name is com. lzj. www. action, there is an action: useraction
The access method is http: // localhost: 8080/strutstest/user.
Page mapped by this action: User. jsp
Access URL analysis:
/User origin: first, name the "/" space available for com. lzj. www. Action, and then get the Resource Name "user" Through useraction"
If the package name is com. lzj. www. Action. test, there is an action: teststrutsaction
The access method is http: // localhost: 8080/strutstest/test-struts.
Page mapped by the action: test-struts.jsp (the page is to be placed under the test folder under the path specified by struts. Convention. Result. path, which is equivalent to converting the space name into a folder)
Possible exceptions:
1. java. Lang. nosuchmethoderror: org. Apache. commons. Lang. stringutils. startswith...
Obviously: the problem lies in commons. Lang. jar:
Possibility: 1. version conflict. There may be two jar packages of different versions.
2. The version is too low (this is what I met ..)
2. java. Lang. noclassdeffounderror: ORG/objectweb/ASM/codevisitor...
Import the ASM-related packages.
Simple implementation of struts Zero Configuration (1)