gpt4 book ai didi

java - 如何在 Struts 2 中进行动态 URL 重定向?

转载 作者:IT老高 更新时间:2023-10-28 21:17:03 26 4
gpt4 key购买 nike

我正在尝试将我的 Struts2 应用程序重定向到生成的 URL。在这种情况下,我希望 URL 使用当前日期,或者我在数据库中查找的日期。所以 /section/document 变成 /section/document/2008-10-06

最好的方法是什么?

最佳答案

我们是这样做的:

在 Struts.xml 中,有一个动态结果,例如:

<result name="redirect" type="redirect">${url}</result>

在行动中:

private String url;

public String getUrl()
{
return url;
}

public String execute()
{
[other stuff to setup your date]
url = "/section/document" + date;
return "redirect";
}

实际上,您可以使用相同的技术使用 OGNL 为 struts.xml 中的任何变量设置动态值。我们已经创建了各种动态结果,包括 RESTful 链接之类的东西。很酷的东西。

关于java - 如何在 Struts 2 中进行动态 URL 重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/173846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com