如何在同一页面上获得结果为什么需要输入? [英] How to get result on same page why input is required?

查看:26
本文介绍了如何在同一页面上获得结果为什么需要输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我正在更新详细信息,因此我创建了操作,但它给了我异常作为响应

In my project I am updating details so I created action, but it gives me exception in response as

No result defined for action org.employee.actions.EmployeeMyProfileAction and result input

struts.xml(之前)

<action name="savePersonalDetails"  class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
        <result name="success">empMyProfile.jsp</result>
</action>

(之后)

<action name="savePersonalDetails" class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
    <result name="success">empMyProfile.jsp</result>
    <result name="input">emp-personal-form.jsp</result>
</action>

Ajax 调用

function checkPersonal(id) {

    if (checkEverythingP()) {
        $.ajax({
            type : 'POST',
            url : 'savePersonalDetails',
            data : $('#personalform').serialize(),
            success : function(data) {
                alert('success');
            },
            error : function() {
                alert('error');
            }
        });
    }
}

它在 JQuery 中给了我成功消息,但它不会进入声明的操作类.我不明白为什么一切都正确后会发生这种情况.我为此提到了许多网站,但没有解决.请告诉我出了什么问题.

It gives me success message in JQuery but It is not going to the action class declared. I didn't understand why it is happening after everything is correct. I referred many sites for this but not resolved. Please suggest me what is going wrong.

推荐答案

并非一切都如你所想的那样正确,因为在 success 回调函数中你已经收到了 INPUT 结果.这个结果由 workflow 返回拦截器,位于 defaultStack - 如果您的操作没有覆盖拦截器配置,则默认使用的拦截器堆栈.它检查操作调用是否存在验证错误,如操作错误或字段错误(转换错误),然后返回由参数 inputResultName 指定的结果.默认情况下,此参数设置为输入".如果拦截器返回结果,它会破坏拦截器链和操作方法的调用.你注意到它说它不会进入声明的动作类.

Not everything is correct as you thought, because in the success callback function you have received INPUT result. This result is returned by workflow interceptor, which is in the defaultStack - the stack of interceptors used by default if your action doesn't override the interceptors configuration. It checks if an action invocation has validation errors like action errors or field errors (the conversion errors) then returns a result specified by the parameter inputResultName. By default this parameter is set to "input". If the interceptor returns a result it breaks a chain of interceptors and invocation of action method. You noted it saying It is not going to the action class declared.

解决方案是覆盖操作的拦截器配置以使用基本堆栈,即没有 validation 和/或 workflow 拦截器.

The solution is to override interceptors configuration of the action to use basic stack, i.e. without validation and/or workflow interceptors.

<action name="savePersonalDetails"  class="org.employee.actions.EmployeeMyProfileAction" method="updateEmployeeDetails">
  <interceptor-ref name="basicStack"/>
  <result name="success">empMyProfile.jsp</result>
</action>

如果您仍然需要执行验证,您可以以编程方式或配置 workflow 拦截器来过滤您的操作方法.仅当您有足够的理由这样做时才应使用最后一个选项,因为它克服了拦截器本身的目的.

If you still need to perform validations you can do it programmatically or configure workflow interceptor to filter your action method. The last option you should use only if you have enough reasons to do so, because it overcomes the purpose of the interceptor itself.

这篇关于如何在同一页面上获得结果为什么需要输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆