struts2支持通过命名约定和annotation实现action配置. struts2 annotation helloworld
使用命名约定和annotation需要依赖convention plugin
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.2.1</version>
</dependency>
struts2通过扫描和转换实现action到java类的匹配
struts, struts2, action, actions的包寻找注解类按照以下顺序确定注解类
com.opensymphony.xwork2.Action接口com.opensymphony.xwork2.ActionSupport类Action结束, 如HelloAction扫描到注解类之后, 执行名字转换实现与action的匹配, 转换顺序如下
Action, 去掉即LoginAction.java最终映射为login.action
默认执行action的execute之后到WEB-INF/content目录下寻找对应的视图.
视图名字为<actionName>-<result>如:login-success, login-input
后缀名可以是jsp, vm, ftl, 框架会按顺序查找
设置struts.convention.result.path可以自定义结果视图默认路径.