Struts2零配置
java-web交流群:132607763
struts2.1开始,支持了零配置。可以不需要struts.xml文件进行配置就可进行配置。
需要添加的包有:
asm-xxx.jar
asm-commons-xxx.jar
struts2-convention-plugin-xxx.jar
这样就完成了零配置。
接着就可以对action用annotation进行配置了。
一个简单的例子:
import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.ParentPackage;import org.apache.struts2.convention.annotation.Result;import com.opensymphony.xwork2.ActionSupport;@ParentPackage("struts2Test")public class LogoutAction extends ActionSupport {private static final long serialVersionUID = -9170674973436664994L;private String name;private String pass;@Action(value="logout", results = {@Result(name=SUCCESS,location="/hello.jsp")})public String execute() {return SUCCESS;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPass() {return pass;}public void setPass(String pass) {this.pass = pass;}}