我可以在同一个动作类中创建两个方法吗?如果是这样,我们如何在 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 中的一个动作类本身中创建多个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!