验证工作正常。在添加操作时加载新表单供用户填写。提交后,验证将在processAdd()上完成。一切都很好。
问题:
用户在http://localhost:8000/Struts2_Spring_Crud/student/add
处填写表单。提交时比处理过的&通过http://localhost:8000/Struts2_Spring_Crud/student/processAdd
验证。如果验证失败,我的网址是/ processAdd。验证失败时我想要/添加。有没有办法做到这一点?
<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>
答案 0 :(得分:1)
试试这个:
<action name="processAdd" class="com.myapp.actions.StudentAction">
<result name="success" type="redirectAction">list</result>
<result name="input" type="redirectAction">add</result>
<result name="failure" type="redirectAction">add</result>
</action>