Interceptor中ValueStack设值的问题

Interceptor,invocation.invoke();之前设值是有效的,之后却失效了,代码如下:
[code="java"]
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = ActionContext.getContext();
ValueStack vs = context.getValueStack();
vs.set("dddd", "ddddddddddd");

    String result = invocation.invoke();

    System.out.println("$$$$$$$$$$"+vs.findString("dddd"));
    vs.set("dddd", "ffffffffffff");
    System.out.println("$$$$$$$$$$"+vs.findString("dddd"));

}

[/code]

console输出结果是对的:
$$$$$$$$$$ddddddddddd
$$$$$$$$$$ffffffffffff

jsp显示是错的:
--> ddddddddddd
谁见过这个问题?
(Interceptor是定义在最下面的,最接近action了)

1个回答

invocation.invoke()后,在vs.set("dddd", "ffffffffffff")之前action就已经执行了
修改如下试试

ActionContext context = ActionContext.getContext();

ValueStack vs = context.getValueStack();

vs.set("dddd", "ddddddddddd");

System.out.println("$$$$$$$$$$"+vs.findString("dddd"));

vs.set("dddd", "ffffffffffff");

System.out.println("$$$$$$$$$$"+vs.findString("dddd"));

String result = invocation.invoke();

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问