【问题标题】:Load same url after validation failed验证失败后加载相同的 url
【发布时间】:2012-10-07 18:38:32
【问题描述】:

验证工作正常。在添加操作时,加载新表单供用户填写。提交后,验证在 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>

【问题讨论】:

    标签: jakarta-ee struts2


    【解决方案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>
    

    【讨论】:

    • 谢谢。工作正常。一个问题。当我在动作之间重定向时,如何重新填充我的文本字段?对此有任何帮助。
    • 我不确定,你的意思是repoplate textfield,但实际上你不需要为此采取行动,请查看我对另一个问题的回答:stackoverflow.com/questions/12765997/…
    • 已回复,请查收。我接受这个答案。请在您的评论中帮助我解决上面的问题链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多