struts中的action类
来源:互联网 发布:软件项目管理模板 编辑:程序博客网 时间:2024/05/17 18:00
Action类
一、实现方式
1、POJO,普通类
2、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;
success : 表示成功了。
none:没有返回值。相当方法void。没有返回值表示没有result,常用与ajax操作。使用response发送数据。
error:服务器异常。
input:表示用户输入错误。
login:表示需要权限。
action:
package cn.itcast.e_action;import com.opensymphony.xwork2.Action;public class Demo1Action implements Action {public String execute() throws Exception {//如果不需要返回结果,就返回none//return NONESystem.out.println("action_Demo1Action");return SUCCESS;}}
原本的:
<struts></package><package name="ns2" namespace="/b" extends="struts-default" ><action name="Demo2Action" class="cn.itcast.d_namespace.Demo2Action" method="execute" ><result name="success" type="dispatcher" >/index.jsp</result></action></package></struts>
实现了action接口后:
<struts><!-- 常量的包 --><package name="action" namespace="/action" extends="struts-default" ><!-- 可以不配置method属性,如果不配置默认走execute方法 --><action name="Demo1Action" class="cn.itcast.e_action.Demo1Action" ><!-- 可以不配置name属性,如果不配置默认走 "success" --><result type="dispatcher" >/index.jsp</result></action><action name="Demo2Action" class="cn.itcast.e_action.Demo2Action" ><!-- 可以不配置name属性,如果不配置默认走 "success" --><result type="dispatcher" >/index.jsp</result></action><!-- class属性也可以不配置. 如果不配置走 com.opensymphony.xwork2.ActionSupport --><action name="Demo3Action"><!-- type属性也可以不配置,默认 就是dispatcher 以下是依据: <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/> --><result >/index.jsp</result></action></package></struts>
3. ActionSupport类,继承类
package cn.itcast.e_action;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionSupport;public class Demo2Action extends ActionSupport {}
二、方法
public String execute(){return SUCCESS;}
1必须是public
2建议有返回值,类型必须String
3方法名称自定义
4没有参数
5需要throw Exception
6非静态的
注意:可以没有返回值,一般情况都有,可以使用return "none" 表示没有返回。
public void add() throw Exception{ }
三、Struts.xml中struts-default包中的默认配置
如果不手动配置Action 默认Action如下配置:
<default-class-refclass="com.opensymphony.xwork2.ActionSupport" />
如果不配置结果的type属性,默认type属性如下配置:
<result-type name="dispatcher"class="org.apache.struts2.dispatcher.ServletDispatcherResult"default="true"/>
0 0
- struts中的action类
- struts中的各种action类
- Struts中的Action方法
- Struts中的action
- 【Struts】Action 2 action类
- struts中action中的种类
- struts中action中的函数
- struts中的action是单态的
- 总结一:jsp调用struts的action类中的map
- Struts之Action类
- Struts的Action类
- struts之action类
- struts笔记:struts action类中的get set 方法的作用
- struts中的action和Action类以及struts2中如何在Action类中获得servlet api的域对象
- 用代码说明Struts 1.0中的action
- struts.xml中的default-action-ref问题
- struts action-mapping中的input的作用
- struts 1 中的DispatchAction-【分派action】
- log4j加载配置
- github的README.md教程
- mysql获取字符串长度的方法
- SQL中的case when then else end用法
- C语言小白
- struts中的action类
- 揭开Socket编程的面纱
- 欢迎使用CSDN-markdown编辑器
- spring中缓存配置
- Jetson TX1板载相机opencv调用打开
- 为什么要写博客
- hihoCoder--1110 正则表达式(区间dp)
- C++使用构造器初始化对象的两种方式
- 将Eclipse的项目转到Android Studio上