struts2笔记08-初识ActionSupport

1、配置一个最简单的action

<action name="simple-action">
<result>/simple.jsp</result>
</action>

 没有class, 没有method,result也没有name属性,但是可以访问成功!肯定是struts2背后偷偷帮我们干了些什么。

2、struts-default.xml

/struts2-core-2.3.28.jar/struts-default.xml

<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />

这里配置了一个默认class,就是ActionSupport.

3、ActionSupport类

查看源代码

public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable

查看Action接口

package com.opensymphony.xwork2;

public interface Action {

    public static final String SUCCESS = "success";

    public static final String NONE = "none";

    public static final String ERROR = "error";

    public static final String INPUT = "input";

    public static final String LOGIN = "login";

    public String execute() throws Exception;
}

 这个Action接口,简单至极,再看ActionSupport实现的execute源码

    public String execute() throws Exception {
return SUCCESS;
}

  

struts2默认就给我们做了这些事,如果我们配置了一个action,没有配置class,就用它了,默认method为execute,result默认name为success. 

上一篇:codevs 1725 探险 (二分)


下一篇:MYSQL 线程池