简体   繁体   中英

How to do a url redirection in Struts1 and Spring

For legacy reasons I need to do a url redirection from an old website to the new one.

For example, this is the old URL:

https://my_old_site/a_section_of_the_website

So when a user types this URL because they think it is still the actual URL, I want to redirect the user to:

https://my_new_site/a_section_of_the_website

I mean, I don't want to redirect to another action, I want to intercept the URL and redirect it to another url. But after searching here, on Google and other sites, I can't figure out how to do it.

I would like to know if there is a way in Struts or Spring to manage the URLs of the application and handle redirects. I don't know if it can be done in the struts.xml or there is another file in Spring in which it performs this task.

Best regards.

Finally, the only thing I have found to achieve this was:

In the Action class of the old URL, as it received HttpServletResponse response as a parameter, I made the redirection there directly and forced a null return since the signature of the method expects an ActionForward .

protected ActionForward doExecute(..., HttpServletResponse response) throws Exception {
    ...
    response.sendRedirect("https://my_new_site/a_section_of_the_website");
    return null;
}

I hope this may be of help to someone in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM