How to do dynamic URL redirects in Struts 2?

后端 未结 6 705
悲哀的现实
悲哀的现实 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:14

    If anyone wants to redirect directly in ActionClass:

    public class RedirecActionExample extends ActionSupport {
    HttpServletResponse response=(HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
    
        url="http://localhost:8080/SpRoom-1.0-SNAPSHOT/"+date;
        response.sendRedirect(url);
        return super.execute(); 
    }
    

    Edit: Added a missing quote.

提交回复
热议问题