使用带有 Stripes 中参数的 POST 方法重定向到另一个站点

发布于 2024-11-29 14:55:55 字数 390 浏览 0 评论 0原文

通常我们可以使用 Stripes 中的 ForwardResolution(path) 重定向到另一个页面,但我想重定向到另一个站点。因此,当我使用 ForwardResolution 时,它将被解释为

http://localhost:8080/MySiteName/<Address of the other site>

我已阅读此链接 ,但是如何给地址添加参数呢?我想将 POST 方法中的变量提交到该站点。是否可以在 Stripes 中使用动作 bean ?

Usually we can redirect to another page using ForwardResolution(path) in stripes, but I want to redirect to another site. So when I am using ForwardResolution it will be interpreted as

http://localhost:8080/MySiteName/<Address of the other site>

I have read this link, but how to add parameters to the address ? I want to submit variables in POST method to that site. Is it possible using an action bean in Stripes ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尬尬 2024-12-06 14:55:55

实际上,您不能使用 ForwardResolution 访问另一个站点。 Forward 是 Servlet 容器内的一个内部概念。您可以做的是 RedirectResolution,您可以使用它向另一个站点发送正常的 GET 查询,包括查询参数。

http://example.com/action?search=thing

但是,这将是一个 GET,不是帖子。

重定向之所以有效,是因为它将 URL 发送到浏览器,然后浏览器将其重新提交到目标站点。

发送 POST 的唯一方法是将填充的 HTML 表单发送到浏览器,操作参数指向新站点和 method="POST",然后使用一点 Javascript 在页面打开时自动提交表单已加载。对于充满隐藏字段的小表单来说,这是相当快的,大多数用户甚至不会看到它发生,但它确实需要在浏览器中启用 JavaScript。

Actually, you can't use a ForwardResolution to go to another site. A Forward is an internal concept within the Servlet container. What you can do is a RedirectResolution, and you can use that to send a normal GET query to another site, including query parameters.

http://example.com/action?search=thing

But, that will be a GET, not a POST.

Redirect works because it sends the URL to the browser, and the browser then resubmits it to the destination site.

The only way to send a POST is to send a populated HTML form to the browser, with the action parameter pointing to the new site and method="POST", and then use a little bit of Javascript to automatically submit the form once the page is loaded. For a small form filled with hidden fields, this is quite fast, most users won't even see it happen, but it does require javascript to be enabled in their browser.

忆沫 2024-12-06 14:55:55

The technologies are different, but the answer to this previous question has a good description of the overall HTTP exchange. One of the strategies mentioned in that answer is for your action to do the post to the third-party site behind the scenes and then redirect to the appropriate location. This could be done via HttpClient or HttpURLConnection instead of the .NET HttpWebRequest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文