当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 字符串。
有没有办法在使用重定向操作时获取此消息而不将其作为查询字符串参数传递?
无法将此消息存储到 session 中。
最佳答案
使用存储拦截器
并将其operationMode
参数设置为AUTOMATIC
,如下所示:
<action name="actionName" class="..." method="...">
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result ..../>
</action>
它会自动将您的消息设置在适当的范围内。对于 redirectAction
结果,它将是 session 范围,但在显示消息后,此拦截器将自动删除它们。
编辑(注释语法):
interceptorRefs={
@InterceptorRef(value="store", params={"operationMode", "AUTOMATIC"}),
@InterceptorRef(value="defaultStack", params={"params.acceptParamNames", "catId, catName, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})
})
关于java - 有没有一种方法可以在使用重定向操作时获取操作类中的属性值,而无需将它们作为查询字符串参数提供?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21576871/