验证工作正常。在添加操作时,加载新表单供用户填写。提交后,验证在 processAdd() 上完成。一切皆好。
问题:
http://localhost:8000/Struts2_Spring_Crud/student/add
用户在提交时填写表格,然后通过 处理和验证http://localhost:8000/Struts2_Spring_Crud/student/processAdd
。如果验证失败,我的 url 是 /processAdd。当验证失败时,我想在 /add 。有没有办法做到这一点?
<s:form action="processAdd" method="POST">
<s:submit method="execute" value="#title"/>
</s:form>
public String execute() throws Exception {
System.out.println("execute() executed");
//Process form data
return SUCCESS;
}
public String input() throws Exception {
System.out.println("input() executed");
//Prepare form data
return INPUT;
}
<default-action-ref name="list"/>
<action name="list" class="com.myapp.actions.StudentAction" method="getAllStudents">
<result name="success" type="tiles">/student.list.tiles</result>
</action>
<action name="add" class="com.myapp.actions.StudentAction" method="input">
<result name="input" type="tiles">/student.edit.tiles</result>
<result name="failure" type="tiles">/student.edit.tiles</result>
</action>
<action name="processAdd" class="com.myapp.actions.StudentAction">
<result name="success" type="redirectAction">list</result>
<result name="input" type="tiles">/student.edit.tiles</result>
<result name="failure" type="redirectAction">add</result>
</action>