Struts2 将参数传递给不同 webapp 中的操作 [英] Struts2 pass parameters to action in different webapp

查看:35
本文介绍了Struts2 将参数传递给不同 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

完全忽略参数.

如果我将结果更改为将所有内容都包含在位置参数中,那么它可以工作,但是您会看到使用多个参数会变得非常笨拙:

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?

推荐答案

如果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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆