Struts2 addActionError 设置结果在重定向结果上自动输入 [英] Struts2 addActionError setting result to input automatically on redirect result

查看:18
本文介绍了Struts2 addActionError 设置结果在重定向结果上自动输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 struts2 操作,它使用 addActionError 设置一些错误,如下所示

I have a struts2 action, which sets some error using addActionError something like below

 public String del() {
        if (new OrdersService().get(idorder) == null) {
            addActionError("Order not found");
        } else {
            new OrdersService().remove(idorder);
            addActionMessage("Order deleted successfully");
        }
        return SUCCESS;
    }

所以上面的方法不管怎样总是返回成功"的结果.

So the above method NO MATTER WHAT always return "success" result.

但是在 struts.xml 中我使用了重定向结果类型来重定向到另一个动作并且该操作永远不会执行,而是我得到结果输入",我无法理解出了什么问题?

But in struts.xml I've used the redirect result-type to redirect to another action and that action is never executed instead I'm getting result "input", I'm unable to understand what's going wrong ?

是不是有点像如果一个动作设置了一个 actionError,另一个动作就不能被执行,并且会直接抛出输入"结果.但这没有意义(至少对我而言)!

Is it something like If an action sets an actionError, another action can't be executed and straight away "input" result will be thrown. But it doesn't make sense (at least to me)!

包括 struts.xml 的某些部分

including some part of struts.xml

<action name="/order/{idorder:[0-9]+}/del" class="actions.OrderAction" method="del">
    <interceptor-ref name="store">
        <param name="operationMode">AUTOMATIC</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack" />

    <result name="success" type="redirect">orders</result>
</action>

推荐答案

默认堆栈包括工作流"拦截器.

The default stack includes the "workflow" interceptor.

如果有操作或字段错误,此拦截器将返回输入"结果,因为存在错误.

If there are action or field errors this interceptor returns the "input" result, because there was an error.

阅读一些文档将为您指明正确的方向.请注意,您的错误无论如何都会在重定向时丢失,除非您专门保存它们.

Reading some documentation will point you in the right direction. Note that your errors will be lost on a redirect anyway, unless you specifically save them.

此外,如果您想重定向到某个操作,请使用actionRedirect"结果类型.

Also, if you want to redirect to an action, use the "actionRedirect" result type.

这篇关于Struts2 addActionError 设置结果在重定向结果上自动输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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