1

POST请求成功时,请求被重定向如下。

private String message; //Getter and setter.

//Required validators.
@Action(value = "AddUpadteCategory",
    results = {
        @Result(name=ActionSupport.SUCCESS, type="redirectAction", params={"namespace", "/admin_side", "actionName", "Category", "currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
        @Result(name = ActionSupport.INPUT, location = "Category.jsp")},
    interceptorRefs={
        @InterceptorRef(value="defaultStack", params={"params.acceptParamNames", "catId, catName, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})
    })
public String insertOrUpdate()
{
    if(true)  //Some conditional check.
    {
         setMessage(getText("message.key.true"));
    }
    else
    {
          setMessage(getText("message.key.false"));
    }

    return ActionSupport.SUCCESS;
}

如果没有发生验证/转换错误,则此消息作为查询字符串参数提供。

有时,此消息可能很长,形成一个长 URL 字符串。

在使用重定向操作时,有没有办法在不将其作为查询字符串参数传递的情况下获取此消息?

将此消息存储到会话中是无法替代的。

4

1 回答 1

1

Use store interceptor and set its operationMode parameter on AUTOMATIC as follows:

<action name="actionName" class="..." method="...">
    <interceptor-ref name="store">
        <param name="operationMode">AUTOMATIC</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack" />
    <result ..../>
</action>

It will automatically set your messages in appropriate scope. For redirectAction result it will be session scope but after displaying your messages this interceptor will automatically remove them.

EDIT (Annotation syntax):

 interceptorRefs={
        @InterceptorRef(value="store", params={"operationMode", "AUTOMATIC"}),
        @InterceptorRef(value="defaultStack", params={"params.acceptParamNames", "catId, catName, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})
    })
于 2014-02-05T13:05:47.047 回答