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

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

问题描述

我正在尝试将我的Struts2应用重定向到生成的网址。在这种情况下,我希望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

最好的方法是什么?

推荐答案

以下是我们的工作方式:

Here's how we do it:

在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天全站免登陆