java - 从 Struts 2 Action 重定向到遗留 Action ?

标签 java url parameters struts2 actionresult

我有一个名为 CustomerAction.java 的 Struts 2 操作,它位于 folderHierarchy/actions/customer 下(customernamespace 这里)。从这个 Action 类中的一个方法,我正在重定向到我的遗留 Action 类

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";
  }

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

所以不是重定向到

/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

最佳答案

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

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

public String getRedirectLocation() {
  return redirectLocation;
}

@Result(name = REDIRECT_TO, location = "${redirectLocation}", type = "redirect") 

关于java - 从 Struts 2 Action 重定向到遗留 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18747020/

相关文章:

php - 具有一个或多个(多个)参数的搜索表单

java - 将元素添加到 ArrayList 的正确位置

java - 关于 javax 与 java 包的一些基本问题

url - 将 URL 路径与 path.Join() 组合

python - 如何使用 python 处理自定义 404 页面

PHP检查对象或类中是否存在属性

php - 是否可以对具有串联变量的查询进行参数化?

java - 如果不是 0 和 1,则返回 false

java - oracle-jdbc数据库变更通知中出现空指针异常

html - 我可以使用纯 CSS 根据 URL 的获取参数设置链接样式吗?