不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法<br />
package com.bjsxt.struts2.front.action; public class IndexAction1 { public String execute() { return "success"; } } 执行过程:
执行IndexAction类里面的execute()后返回success,然后根据返回的字符串查找对应的jsp页面。如果不修改resault里面的name属性,默认就为success
写IndexAction的三种方法:
(1)
public class IndexAction1 { public String execute() { return "success"; } } (2)实现Action接口
public class IndexAction2 implements Action { public String execute() { return "success"; } } (3) 继承ActionSupport类(真正开发中用),因为ActionSupport中已经封装好了一些特别调用的方法
public class IndexAction3 extends ActionSupport { public String execute() { return "success"; } } 查看struts 的xwork源码可知:默认返回success
ActionSupport实现了Action接口