问题
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.
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 ?
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)!
[EDIT] 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>
回答1:
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.
Also, if you want to redirect to an action, use the "actionRedirect" result type.
回答2:
public String del() {
if (new OrdersService().get(idorder) == null) {
addActionError("Order not found");
return ERROR;
} else {
new OrdersService().remove(idorder);
addActionMessage("Order deleted successfully");
return SUCCESS;
}
}
Also include return type 'error' as you have done for return type 'success' in your action mapping in struts.xml
来源:https://stackoverflow.com/questions/16049813/struts2-addactionerror-setting-result-to-input-automatically-on-redirect-result