【Struts2复习知识点三】-Action的配置
2012-08-14 12:14
633 查看
具体视图的返回可以由用户自己定义的Action来决定
具体的手段是根据返回的字符串找到对应的配置项,来决定视图的内容
具体Action的实现可以是一个普通的java类,里面有public String execute方法即可
或者实现Action接口
不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法
struts.xml
IndexAction1.java(只是一个普通类)
IndexAction2.java(实现了Action接口)
IndexAction3.java(继承了ActionSupport)
具体的手段是根据返回的字符串找到对应的配置项,来决定视图的内容
具体Action的实现可以是一个普通的java类,里面有public String execute方法即可
或者实现Action接口
不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法
struts.xml
<constant name="struts.devMode" value="true" /> <package name="front" extends="struts-default" namespace="/"> <action name="index" class="com.bjsxt.struts2.front.action.IndexAction1"> <result name="success">/ActionIntroduction.jsp</result> </action> </package
IndexAction1.java(只是一个普通类)
public class IndexAction1 { public String execute() { return "success"; } }
IndexAction2.java(实现了Action接口)
import com.opensymphony.xwork2.Action; public class IndexAction2 implements Action { @Override public String execute() { return "success"; } }
IndexAction3.java(继承了ActionSupport)
import com.opensymphony.xwork2.ActionSupport; public class IndexAction3 extends ActionSupport { @Override public String execute() { return "success"; } }
相关文章推荐
- 【Struts2复习知识点三】-Action的配置
- 【Struts2复习知识点十四】-默认Action的配置
- 【Struts2复习知识点七】-用Action的属性接收参数
- 【Struts2复习知识点十三】-模块包含——配置struts.xml
- 【Struts2复习知识点一】-配置struts2环境
- 【Struts2复习知识点二】-namespace的配置
- 【Struts2复习知识点一】-配置struts2环境
- 复习struts2之Action配置的各项默认值
- 【Struts2复习知识点二】-namespace的配置
- 复习struts2之基于XML配置方式实现对action的所有方法进行校验
- 复习struts2之配置action范围国际化资源文件
- Struts2中struts.xml的Action配置详解(一)===》 struts2.0中struts.xml配置文件详解 (二)==》Struts2_struts.xml配置及例程三
- Struts2中Action配置的默认值和result配置的转发类型
- struts2 action跳转action 的配置方法
- Struts2_配置Action
- struts2配置文件中action的name属性
- Struts2中action重定向跳转到jsp页面两种配置方式
- Struts2_基于注解的Action配置
- Struts2配置详解_配置Action之通配符映射
- (复习)Struts2配置和简单案例(二)