First add Lib:
<Dependency> <groupId>Org.apache.struts</groupId> <Artifactid>Struts2-config-browser-plugin</Artifactid> <version>2.3.20</version> </Dependency> <Dependency> <groupId>Org.apache.struts</groupId> <Artifactid>Struts2-convention-plugin</Artifactid> <version>2.3.20</version> </Dependency>
Access Http://localhost:8080/conv/config-browser/a.action to see all the paths that are currently mapped
The plugins are executed in the following order:
1. Look for the following packages:,, struts
struts2
action
,actions
任何深度找到的以上包都自动作为根目录
2.然后在包内寻找以下类:实现了com.opensymphony.xwork2.Action
或者继承了com.opensymphony.xwork2.ActionSupport,或类名以Action结尾
3.映射为url:
Com.example. actions. Mainaction,/maincom.example. actions. Products. Display,/products/displaycom.example. struts. Company.details.ShowCompanyDetailsAction-/company/details/show-company-details (all lowercase)
Like what
Will map to,
You can skip some packages: struts.convention.exclude.packages
=org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*, Org.springframework.web.struts2.*,org.hibernate.* (skipped packages are no longer added, even if manually added)
Auto-Search Package name: struts.convention.package.locators
=action,actions,struts,struts2
Automatically search for package names beginning with: struts.convention.package.locators.basepackage=
Auto-search End of class name: Struts.convention.action.suffix=action
To specify a specific package manually: struts.convention.action.packages=
4. Default, all the result is here to find:web-inf/content
For example, you can access the http://localhost:8080/conv/my-jsp.action through the
Can be controlled by constant: struts.convention.result.path
=/web-inf/content/
Depending on the return type and the return string, a different name is required:
5. If the page file cannot be found, it is considered an action, and the other action can add @action ("XX") to the method, indicating the specific path, which is the result type chain
As in,
Public class extends Actionsupport { public String execute () { return ' here "; }}
Public class extends actionsupport { @Action ("my-jsp-here")//by specifying a specific path to implement chain, provided that the page file is not public String execute () { return "yes"; }}
will eventually become,
You can set automatic overloading:
<
constant
name="struts.devMode" value="true"/>
<
constant
name="struts.convention.classes.reload" value="true" />
Struts.convention.action.alwaysMapExecute =false Disable automatic call to execute ()
Struts.convention.action.disablescanning=true Disabling scanning
Struts.convention.action.mapAllMatches =true No @action also auto map
Struts.convention.action.name.lowercase=false don't turn into lowercase
Struts.convention.action.name.separator=_ Name Separator
Struts.convention.action.eagerloading=true improves performance when you don't use spring
Struts Convention Plugin Process (2.1.6+)