Struts 2.3 - redirect against redirectAction

What is the main difference between redirect and redirectAction in the context of Struts2.3.

I saw below the urls for redirect and redirectAction .

I understand the following points:

  • redirection is similar to sendRedirect () method. A new query is created that clears the previous value stack and the action (action instance, action errors, field errors, etc.) are no longer available.
  • In redirectAction control transfers to another action (in the same or different package)
  • redirectAction recommended to redirect.

But when I implemented both of the above examples, I only had to change struts.xml .

  • In both cases, the action is no longer available,
  • A new request has been created,
  • The generated URL was the same.

Firstly, I am confused with an operator written in the Apache redirectAction documentation

This is better than ServletRedirectResult because it does not require you to encode the URL patterns processed by ActionMapper into your struts.xml configuration files. This means that you can change your URL patterns anywhere, and your application will still work. It is highly recommended that if you are redirected to another you use this result, and not the standard redirect result.

Secondly, I still do not very clearly understand the difference between the two.

+4
source share
2 answers

The difference is obvious: redirectAction is another type of result that extends the result type of redirect by providing actionName , namespace and method attributes. These attributes are used to create the URI used to replace the location attribute of the redirect result type.

The operation is OK, it’s better to build the URL from ActionMapping , which is implemented by the result type redirectAction instead of manually coding it. Even manually, always use UrlHelper instead of hardcoding. In JSP, always use the s:url tag.

+2
source

One redirects to actions, one redirects to arbitrary resources.

actionRedirect better for most Struts 2 applications, since most redirects will occur with locations inside the application, and all you need to provide is the name of the action from its map.

You can do the same with a simple redirect , but you will need to provide an action extension, if any, so it's a little ugly and a bit ore brittle (for example, if the action extension changes, although this rarely happens).

+1
source

All Articles