Struts2中Action中是否需要实现Execute方法
作者:SimonMaxs 时间:2021-10-30 06:57:23
今天有朋友问我Struts2中Action必须实现execute方法吗?顺利的回答出来了。
其实分两种情况:
1)如果你的Action类是继承自ActionSupport或是BaseAction的话,确切的说是重写了execute方法,ActionSupport里的默认实现就是返回"success"视图。因此,你可以不实现execute方法,只要你的struts.xml里有"success"对应的result即可。
<action name="doRevenuesMaintenance">
<interceptor-ref name="novatar-webStack-baseparam">
<param name="security.actionType">PRIVATE</param>
</interceptor-ref>
<result name="success">incomeMaintenance.jsp</result>
< /action>
这段代码中就是通过action的配置文件来控制跳转页面。在action的类中没有execute()方法重写。
2)如果你的Action类没有继承ActionSupport或是BaseAction的话,而你又没有在struts.xml中对应<action>标签中用method属性指定你自己的方法的话,默认就要找execute方法,这时是必须要实现execute方法的,否则Struts2会找不到对应的方法而报错。
不过,大部分情况下都是继承ActionSupport的(比如输入验证、文件上传等功能就要求必须继承)。还有,不管你写没写execute方法,还是可以用<action>标签的method属性指定其他方法的。
以上所述是小编给大家介绍的Struts2中Action中是否需要实现Execute方法的相关介绍,希望对大家有所帮助!
标签:struts2,action,execute,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring interceptor拦截器配置及用法解析
2023-06-26 06:08:15
java 并发线程个数的如何确定
2022-01-01 21:52:13
Java技能点之SimpleDateFormat进行日期格式化问题
2023-09-09 01:50:26
![](https://img.aspxhome.com/file/2023/9/58339_0s.jpg)
Java Synchronized锁失败案例及解决方案
2023-10-25 12:33:47
![](https://img.aspxhome.com/file/2023/3/61863_0s.png)
实例讲解Java读取一般文本文件和word文档的方法
2023-11-13 05:09:53
Java去掉数字字符串开头的0三种方法(推荐)
2022-05-31 08:04:41
Java背包问题求解实例代码
2023-10-05 06:20:33
Java RandomAccessFile 指定位置实现文件读取与写入
2023-06-05 17:06:25
Spring-boot 2.3.x源码基于Gradle编译过程详解
2022-04-07 15:41:36
![](https://img.aspxhome.com/file/2023/2/66032_0s.png)
Java线程池 ThreadPoolExecutor 详解
2021-05-24 10:35:42
![](https://img.aspxhome.com/file/2023/2/64392_0s.jpg)
java环境变量path和classpath的配置
2023-08-31 01:09:04
![](https://img.aspxhome.com/file/2023/5/58205_0s.jpg)
Java序列化和反序列化示例介绍
2023-11-25 04:24:26
详解Flutter桌面应用如何进行多分辨率适配
2023-06-17 07:14:59
Jackson多态序列化图文详解
2022-01-26 19:46:08
![](https://img.aspxhome.com/file/2023/1/69891_0s.jpg)
SpringBoot整合Shiro的代码详解
2023-10-30 10:53:31
JPA save()方法将字段更新为null的解决方案
2023-10-28 22:29:28
SpringBoot遇到的坑@Qualifier报红的解决
2022-06-03 07:49:55
![](https://img.aspxhome.com/file/2023/5/66965_0s.png)
SpringMVC请求流程源码解析
2021-08-07 03:35:11
![](https://img.aspxhome.com/file/2023/3/64533_0s.jpg)
分析并发编程之LongAdder原理
2023-05-11 17:19:30
![](https://img.aspxhome.com/file/2023/9/65599_0s.jpg)
如何在mapper文件中使用in("str1","str2")
2023-07-10 10:40:51
![](https://img.aspxhome.com/file/2023/0/57610_0s.jpg)