Struts 2.3 - redirect vs redirectAction

喜欢而已 提交于 2019-12-01 07:21:45

The difference is obvious: redirectAction is just another result type, which extends redirect result type providing the attributes actionName, namespace, and method. These attributes used to build the URI used to substitute for the location attribute of the redirect result type.

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

One redirects to actions, one redirects to arbitrary resources.

actionRedirect is better for most Struts 2 applications since most redirects will happen to locations inside the application, and all you need to supply is the action name from its mapping.

You could do the same thing with a plain redirect, but you'd need to supply the action extension, if any, so it's a bit uglier and a bit ore fragile (e.g., if the action extension changes, although that happens rarely).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!