WebWork中动态生成Result

来源:互联网 发布:网络暴力的成因 编辑:程序博客网 时间:2024/05/25 08:15

当在xwork.xml中配置<action>时,在<result>部分可以写成这样:
......
<result name="success" type="redirect">
    <param name="location">/${path}</param>
 </result>
......
其中,${}包含了一个ognl表达式,从WebWork的OgnlValueStack中获取内容,进而动态生成内容。
在Action中可以这样写:
......
private String path;
 
public String getPath(){
  return path;
}
 
public String execute() throws Exception {
  //把下面的代码解除注释可以在stack中存储其它的对象
 //HttpServletRequest request=ServletActionContext.getRequest();
 //OgnlValueStack stack=ServletActionContext.getValueStack(request);
 path="success.jsp";
 return SUCCESS;
}

由于Action会位于栈顶,因此"${path}"会调用getPath()方法,获得"success.jsp",动态生成结果"/success.jsp"。