如何在 Struts 2 中进行动态 URL 重定向? [英] How to do dynamic URL redirects in Struts 2?

查看:28
本文介绍了如何在 Struts 2 中进行动态 URL 重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to have my Struts2 app redirect to a generated URL. In this case, I want the URL to use the current date, or a date I looked up in a database. So /section/document becomes /section/document/2008-10-06

最好的方法是什么?

推荐答案

我们的做法如下:

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

In Struts.xml, have a dynamic result such as:

<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 链接之类的东西.很酷的东西.

You can actually use this same technology to set dynamic values for any variable in your struts.xml using OGNL. We've created all sorts of dynamic results including stuff like RESTful links. Cool stuff.

这篇关于如何在 Struts 2 中进行动态 URL 重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆