Struts2将参数传递给不同Webapp中的操作 [英] Struts2 pass parameters to action in different webapp
问题描述
我使用Struts 2.3.16.3.我希望webapp 1中的操作将参数传递给webapp 2中的操作.在webapp 1的struts.xml中,我定义了以下结果:
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>
当结果等于成功"时,我希望浏览器将我重定向到此网页(webapp2中的页面):
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
完全忽略该参数.
如果我将结果更改为将所有内容都包含在location参数中,则它可以工作,但是您可以看到,使用多个参数时,这变得很笨拙:
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>
这可以将我的浏览器正确重定向到该URL:
This correctly redirects my browser to the url:
http://localhost:8080/Webapp2/index.action?testParam=testValue
为什么第一种方法不起作用?
Why does the first method not work?
推荐答案
如果 location
以 http:
, https:
, mailto:
, file:
, ftp:
,然后将其用作使用 response.sendRedirect()
进行重定向的最终位置.在这种情况下,使用< param>
标记的结果中的参数将被忽略.
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.
这篇关于Struts2将参数传递给不同Webapp中的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!