How to do dynamic URL redirects in Struts 2?

后端 未结 6 708
悲哀的现实
悲哀的现实 2020-11-28 04:57

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/

6条回答
  •  情书的邮戳
    2020-11-28 05:19

    Here's how we do it:

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

    ${url}
    

    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.

提交回复
热议问题