如何在 Struts 2 的操作类中使用 Result 注释重定向到不同的命名空间

问题描述 投票:0回答:1

我有一个包含公共区域和保护区的网站。它是使用 Struts 2 (2.5.30) 和 Convention Plugin (2.5.30) 设置的。

在我的一项操作中,我尝试使用结果注释从公众 (

/pub/enrollmentAction
) 重定向到保护区中的另一项操作 (
/prot/CompleteEnrollmentAction
)。

执行重定向时,它会将

/pub
添加到结果 URL 中。即
/pub/prot/complete-enrollment
。应该是
/prot/complete-enrollment

EnrollmentAction

@Action(results = { @Result(name = "success", location = "/prot/complete-enrollment", type = "redirectAction") }, interceptorRefs = { @InterceptorRef("BasicStack") })
public class Enrollment extends ActionSupport {
  
  @Override
  public String execute() throws Exception {
    
    return "success";
  }

我尝试在每个类中添加

@namespace
注释,但没有成功。 我尝试将结果放入
struts.xml
,但没有正确解析。

如果我输入重定向的 URL,我可以手动点击它。

java annotations struts2 struts2-convention-plugin
1个回答
0
投票

由于您使用约定插件,您需要知道如何按约定创建配置。该插件也有自己的配置,如果更改,可能会影响您的代码。

您错误地使用了结果配置。如果您想使用 redirect

 属性,则应该有 
location
 result
类型。
redirectAction
result
类型中没有这样的属性。

@Result(name = "success", location = "/prot/complete-enrollment", type = "redirect")

如果您想使用

redirectAction
结果类型,那么

@Result(name = "success", namespace = "/prot", actionName = "complete-enrollment", type = "redirectAction")
© www.soinside.com 2019 - 2024. All rights reserved.