struts 中继承ActionSupport类
由JavaDoc可知,ActionSupport类实现了接口。
com.opensymphony.xwork2.Action。
com.opensymphony.xwork2.LoaleProvider。
com.opensymphony.xwork2.TextProvider。
com.opensymphony.xwork2.Validateable。
com.opensymphony.xwork2.ValidationAware。
com.uwyn.rife.continuations.ContinuableObject。
例如下例所示:
public class HelloWorld extends ActionSupport {
private String message;
/HelloWorld.jsp
在默认情况下,当请求HelloWorld.do发生时,Struts 2会根据struts.xml里的Action映射集(Mapping)实例化tutoiral.HelloWorld类,并调用其execute()方法。当然,我们可以通过以下两种方法改变这种默认调用,这个功能(Feature)有点类似Struts 1中的LookupDispathAction。
在sturts.xml中新建Action,并指明其调用的方法。
访问Action时,在Action名后加上”!xxx”(xxx为方法名)。
例如我们可以在tutorial/HelloWorld.java中加入以下方法:
public String aliasAction() {
message =”自定义Action调用方法”;
return SUCCESS;
}
然后可以在sturts.xml中指定method来设置请求的函数名: