Create multiple methods in one action class itself in Struts2?(在 Struts2 中的一个动作类本身中创建多个方法?)
问题描述
我可以在同一个动作类中创建两个方法吗?如果是这样,我们如何在 struts.xml
文件中指定它?
Can I create two methods in the same Action Class? If so how can we specify it in the struts.xml
file ?
例如:我创建了一个简单的验证操作类来验证 email address
以及 password
使用两个单独的正则表达式.我在 Action 类中创建了两个方法:emailVerification()
和 passVerification()
.我在里面编写了所有必要的验证代码,但是现在当它们返回 SUCCESS
时,它们应该会产生相同的成功页面结果,对于 ERROR
也是如此..
For example : I created a simple validation action class to validate the email address
as well as password
using two separate regular expression.
I created two Methods in the Action class say: emailVerification()
and passVerification()
.
I wrote all the necessary validation code inside, but now when they return SUCCESS
they should result into the same success page result and for ERROR
likewise..
推荐答案
是的,您可以在 Action Class 中创建任意数量的方法.你可以这样做
Yes you can create any number of methods in an Action Class. You can do something like this
package com.myvalidation;
public class MyValidationClass extends ActionSupport
{
public String emailVerification() throws Exception
{
//Your validation logic for email validation
return SUCCESS;
}
public String passVerification() throws Exception
{
//Your validation logic for password validation
return SUCCESS;
}
}
struts.xml
<action name="emailVerification" method="emailVerification" class="com.myvalidation.MyValidationClass">
<result name="success">/your_success_jsp.jsp</result>
<result name="input">/your_error_jsp.jsp</result>
</action>
<action name="passVerification" method="passVerification" class="com.myvalidation.MyValidationClass">
<result name="success">/your_success_jsp.jsp</result>
<result name="input">/your_error_jsp.jsp</result>
</action>
这篇关于在 Struts2 中的一个动作类本身中创建多个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Struts2 中的一个动作类本身中创建多个方法?


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01