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
What's the best way to do this?
Here's how we do it:
In Struts.xml, have a dynamic result such as:
<result name="redirect" type="redirect">${url}</result>
In the action:
private String url; public String getUrl() { return url; } public String execute() { [other stuff to setup your date] url = "/section/document" + date; return "redirect"; }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With