2

I have been searching web for hours, and I can't find answer to a simple question in Struts 2. Basically, I have the following action in Struts 1 which is a simple forward, and I want to reproduce the same in Struts 2:

<action path="/az/api/v22/my-tenants" forward="/components/c/apis/v22/my-tenants.jsp">
      </action>

I could write an action class to do this, but I think Struts2 has to have some way of doing this without having to write an action class since it is is a simple redirection.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Sam Blake
  • 29
  • 3

1 Answers1

2

Create actionless result in the struts.xml

struts.xml:

<package name="v22" namespace="/az/api/v22" extends="struts-default">
    <action name="my-tenants">
        <result>/components/c/apis/v22/my-tenants.jsp</result>
    </action>
</package>

This configuration defines a package with namespace /az/api/v22 and action name my-tenants. So if you use path /az/api/v22/my-tenants it will be mapped to the action config above, because default action mapper is using namespace and action name together to get the action config.

There's no class attribute in the action tag, and it uses class ActionSupport instead. This class is configured by default in struts-default package.

In the result it's enough to define the location of the JSP, because struts2 defaults are using a dispatcher that forwards to JSP, and it's using "success" result code by default in the result config which is returned by default by ActionSupport class.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Can be this done without using the namespace attribute of the package. The problem is that a package in Struts2 has already been created that these calls are going to be part of it. So, I don't have control over the package's namespace. –  Jul 14 '16 at 17:54
  • Without namespace attribute you are missing a part that should be added before the action name. – Roman C Jul 14 '16 at 20:15