2

我有 Struts 2 动作CustomerAction.java,命名为 folderHierarchy/actions/customercustomernamespace此处)。从这个动作类中的一个方法,我重定向到我的旧动作类

Result映射是:

@Result(name = "redirectTo", location = "#parameters.redirectLocation", type = "redirect") })

其中的#parameters.redirectLocation值为

/customerhome.do?custIdId=200

Action方法是:

 @Action(value = "CustomerAction!redirectToPage")
  public String redirectToLocation() {
    return "redirectTo";
  }

但问题是 strutscustomer在重定向位置之前自动添加当前操作命名空间(即)。

所以而不是重定向到

/myWebApp/customerhome.do?custIdId=200,

Struts 2 重定向到

/myWebApp/customer/customerhome.do?custIdId=200

我不明白为什么要添加customer名称空间以及如何摆脱它?

我也试过:

@Result(name = "redirectTo", location = "#parameters.redirectTo", type = "redirect", params = { "namespace", "/" }) })

但它也没有用。

另一个观察结果是:

什么有效:

@Result(name = ComposeMessageCrudAction.REDIRECT_TO, location = "/customerhome.do?custIdId=200", type = "redirect") })

什么不起作用:

@Result(name = "redirectTo", location = "#parameters.redirectLocation", type = "redirect") })

其中的#parameters.redirectLocation 值为

/customerhome.do?custIdId=200

我不明白为什么第二种方法不起作用以及为什么它customer之前添加了命名空间

/customerhome.do?custIdId=200

4

1 回答 1

0

使用location属性的值作为 struts 结果的动态参数。

private String redirectLocation = "/customerhome.do?custIdId=200";

public String getRedirectLocation() {
  return redirectLocation;
}

@Result(name = REDIRECT_TO, location = "${redirectLocation}", type = "redirect") 
于 2013-09-11T20:11:52.657 回答