[code="java"]
package interceptor;
import action.EAction;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.AroundInterceptor;
public class ConvertInterceptor extends AroundInterceptor {
public String intercept(ActionInvocation invocation) throws Exception {
before(invocation);
String result = invocation.invoke();
after(invocation, result);
return result;
}
protected void after(ActionInvocation actionInvocation, String s) throws Exception {
}
protected void before(ActionInvocation actionInvocation) throws Exception {
Action action = actionInvocation.getAction();
if(action instanceof EAction) {
EAction eAction = (EAction) action;
eAction.setParam("hello, world"); //你要修改的参数名称
}
}
}
[/code]
假如说下面就是你要修改的Action
[code="java"]
package action;
import com.opensymphony.xwork.ActionSupport;
public class EAction extends ActionSupport {
public String execute() throws Exception {
System.out.println("param = " + param);
return SUCCESS;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
private String param;
}
[/code]
另外,把这个interceptor放到你的所有的interceptor之后就可以了,例如
[code="xml"]
<interceptor-stack name="myStack">
<interceptor-ref name="completeStack"/>
<interceptor-ref name="convertInterceptor"/>
</interceptor-stack>
[/code]