Struts2笔记 - 命名空间和Action的三种创建方法

发布于 2011-06-18 | 更新于 2025-06-14

1、命名空间Namespace

namespace缺省情况下相当于:namespace=””;

2、Action创建的三种方法:

2.1、直接创建一个类提供一个execute()方法并返回字符串:

public class IndexAction1 {
public String execute() {
return “success”;
}
}

只要在类中提供了execute方法,返回类型为字符串,Struts2中就可以当做一个Action使用。

2.2、继承Action并实现execute()方法:

public class IndexAction1 implements Action {
@Override
public String execute() {
return “success”;
}
}

2.3、继承ActionSupport:

public class IndexAction1 extends ActionSupport {
@Override
public String execute() {
return “success”;
}
}

一般使用第三种方法,接下来是在struts.xml文件中该配置:

/ActionIntroduction.jsp

本文作者: arthinking

本文链接: https://www.itzhai.com/struts2-notes-three-ways-to-create-naming-space-and-action.html

版权声明: 版权归作者所有,未经许可不得转载,侵权必究!联系作者请订阅本站。

×
帅旋DevShow

订阅及时获取网站内容更新。

充电

当前电量:100%

帅旋DevShow

订阅我,及时获取网站内容更新。