3

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?

user1884155
  • 3,616
  • 4
  • 55
  • 108
  • Shouldn't type be redirectAction instead of redirect ? – mprabhat Nov 26 '14 at 16:25
  • I thought not, because redirectAction only allows you to redirect to another action within the same webpp. My request is going to another webapp. – user1884155 Nov 26 '14 at 16:29
  • Check the answer given [here](http://stackoverflow.com/questions/11006341/passing-parameters-in-url-while-redirecting-in-struts2) – mprabhat Nov 26 '14 at 16:33
  • Seems your second app doesn't like those parameter. – Roman C Nov 26 '14 at 16:37
  • @mprabhat I tried the solution in that answer (which puts the params directly in the location url instead of as a separate param) and that works. However, it still doesn't explain why the normal approach doesn't work – user1884155 Nov 26 '14 at 16:51
  • Http Redirect will not take any parameters, so only way to do is through query String – mprabhat Nov 26 '14 at 16:52
  • I thought struts2 would make the complete url for me (automatically converting the params to url query parameters for me), and only then send out the request to go that location. Am I wrong in this assumption? See the manuel here: http://struts.apache.org/release/2.2.x/docs/redirect-result.html The only difference between my code and the example in manual is my code redirects to an action in ANOTHER webapp. – user1884155 Nov 26 '14 at 16:55
  • For http redirect and post parameter, please check this [question](http://programmers.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect) – mprabhat Nov 26 '14 at 16:56
  • @RomanC I edited the question, I made it work with an alternative way. looks like the parameters themself are perfectly fine. It's the 'param' tag that doesn't work when redirecting. Why? – user1884155 Nov 26 '14 at 16:57
  • @mprabhat Thanks for that additional information, but I'm not posting anything. I'm doing an ordinary GET. I just want Struts2 to build the query string for me, just like in this example: struts.apache.org/release/2.2.x/docs/redirect-result.html. I don't understand why the example doesn't work for me. – user1884155 Nov 26 '14 at 17:00
  • An alternative way seems to me a correct way, btw some part of your application fails to get parameters from the result. – Roman C Nov 26 '14 at 17:19
  • @RomanC Webapp1 can find the values of parameters. Webapp2 can receive them. this is all demostrated by the alternative approach I added in the question. What I wonder is why the 'params' tag is not working. It is NOT the ognl expression ${} that doesn't work, because that works just fine. – user1884155 Nov 26 '14 at 18:09
  • Did you try this resultset with the same application? – Roman C Nov 26 '14 at 18:27

1 Answers1

1

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176