Struts2 pass parameters to action in different webapp

436 views Asked by At

I use Struts 2.3.16.3. I want an action from webapp 1 to pass parameters to an action in webapp 2. In the struts.xml of webapp 1 I define the following result:

<result name="success" type="redirect">
    <param name="location">http://localhost:8080/Webapp2/index.action</param>
    <param name="testParam">testValue</param>
</result>

I expect my browser to redirect me to this webpage (a page in webapp2) when the result equals 'success':

http://localhost:8080/Webapp2/index.action?testParam=testValue

However, my browser takes me to:

http://localhost:8080/Webapp2/index.action

completely ignoring the parameter.

If I change my result to have everything inside the location param then it works, but you can see this gets very clunky with multiple params:

<result name="success" type="redirect">
    <param name="location">http://localhost:8080/Webapp2/index.action?testParam=${testValue}</param>
</result>

This correctly redirects my browser to the url:

   http://localhost:8080/Webapp2/index.action?testParam=testValue

Why does the first method not work?

1

There are 1 answers

0
Roman C On BEST ANSWER

If the location starts with http:, https:, mailto:, file:, ftp: then it's used as a final location to redirect using response.sendRedirect(). Parameters in the result using <param> tag in this case are ignored.