How to do dynamic URL redirects in Struts 2?

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

    One can redirect directly from an interceptor without regard to which action is involved.

    In struts.xml

        
            ${#request.redirUrl}
        
    

    In Interceptor

    @Override
    public String intercept(ActionInvocation ai) throws Exception
    {
        final ActionContext context = ai.getInvocationContext();        
        HttpServletRequest request = (HttpServletRequest)context.get(StrutsStatics.HTTP_REQUEST);
        request.setAttribute("redirUrl", "http://the.new.target.org");
        return "redir";
    }
    

提交回复
热议问题