我正在开发 struts 1.1 应用程序。
我已经为 JSP 表单页面(即 adduser.jsp)添加了验证。
单击添加按钮后,它会得到验证。我在“Validator-XSS.xml”中的验证工作正常。
但是当验证失败时,它会转发到输入属性,即 jsp 表单页面(即 adduser.jsp)。
在这里,我需要将调用转发到另一个
打开 JSP 表单页面(即 adduser.jsp)的操作(ieopenAddUser.do)。
更新
struts-config.xml
<struts-config>
<!-- some another entries -->
<form-bean name="UserForm" type="com.UserForm"/>
<action path="/createuser" type="com.CreateUserAction" name="UserForm"
scope="request">
<forward name="adduser" path="/jsp/adduser.jsp"/>
</action>
<action path="/adduser" type="com.AddUserAction" input="/jsp/adduser.jsp"
name="UserForm" scope="request">
<forward name="showuser" path="/showUserDetails.do"/>
</action>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/User-Validator.xml"/>
</plug-in>
</struts-config>
XSS-validator.xml
<form-validation>
<formset>
<form name="UserForm">
<field property="userName" depends="mask">
<msg name="mask" key="ui.field.invalidvalue" bundle="appResources"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z0-9-_]*$</var-value>
</var>
</field>
</form>
</formset>
单击在 jsp 文件中创建用户时,它将调用createuser.do在表单中输入详细信息后将打开 adduser.jsp,然后单击添加按钮,它将adduser.do 也通过 XSS-validator.xml 进行验证,但调用转到jsp /adduser.jsp但我需要它必须调用createuser.do
ActionForm is extended by ValidatorForm
public class UserForm extends ValidatorForm{
String userName;
String userId;
//getter setter
}
ActionClass
Public Class CreateUserAction{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
//some code to bring list and other details
mapping.findForward("adduser");
}
Public Class AddUserAction{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
//some code to add user and other details
mapping.findForward("showuser");
}