我有一个 HTML 表单,我正在尝试使用 Struts 来验证用户在网站上注册之前是否输入了有效的电子邮件地址。
提交表单时,似乎不会发生任何验证,并且表单只是按原样提交给操作参数类。
我是 Struts 的新手,所以请假设我错过了显而易见的事情(因为我可能已经错过了)。
我的表单看起来像这样(UserRegistrationAddForm.jsp):
<form name="registrationAddForm" method="post" action="UserRegistrationAdd">
<div class="form-label-holder">
<label for="email"><fmt:message key="LOGON_ID" bundle="${storeText}" /><span class="mandatoryindicator"> *</span></label>
</div>
<div class="form-field-holder">
<input id="email" class="required email" type="text" name="logonId" value="<c:out value="${paramSource.logonId}" />" />
</div>
<input type="image" src="<c:out value="${jspStoreImgDir}" />mobile/images/next-button.png" />
</form>
我的配置是(struts-config.xml):
<struts-config>
<form-beans>
<form-bean name="UserRegAddForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="logonId" type="java.lang.String" />
</form-bean>
</form-beans>
<action
parameter="com.example.UserRegistrationAddCmd"
path="/UserRegistrationAdd" type="com.example.LTPATokenGenerationEnabledBaseAction"
name="UserRegAddForm">
<set-property property="https" value="0:1"/>
<set-property property="authenticate" value="0:0"/>
</action>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml"/>
</plug-in>
</struts-config>
将验证配置为 (validator-rules.xml):
<form-validation>
<form name="UserRegAddForm">
<field property="logonId" depends="required,email">
<arg key="registrationAddForm.logonId" />
</field>
</form>
</form-validation>
堆栈显示:
at com.example.BaseAction.executeAction(BaseAction.java:722)
at com.example.struts.BaseAction.execute(BaseAction.java:150)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at com.example.struts.ECActionServlet.processRequest(ECActionServlet.java:218)
at com.example.struts.ECActionServlet.doPost(ECActionServlet.java:174)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
堆栈跟踪来自下一步处理的错误,所以它不应该走那么远。
有趣的是,堆栈没有提到对我的操作类型的任何引用,com.example.LTPATokenGenerationEnabledBaseAction
所以我假设我配置错误?