0
驗證工作正常。在添加動作加載新表單以供用戶填寫。一旦提交,就在processAdd()上完成驗證。一切皆好。驗證失敗後加載相同的網址
問題:
用戶填寫表格在提交不是通過http://localhost:8000/Struts2_Spring_Crud/student/processAdd
驗證處理& http://localhost:8000/Struts2_Spring_Crud/student/add
。當。如果驗證失敗,我的網址是/ 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>
感謝。工作正常。一個問題。當我在兩次操作之間重定向時,如何重新填充我的文本字段?對此有任何幫助。 – Pirzada
我不知道,你是什麼意思'repoplate textfield',但實際上你不需要爲此操作,請查看我的另一個問題的答案:http://stackoverflow.com/questions/12765997/struts2-disable驗證頁面加載 – Jaiwo99
已回覆請檢查。我接受這個答案。請在您的評論中提供以上問題鏈接。 – Pirzada