使用带有 Stripes 中参数的 POST 方法重定向到另一个站点
通常我们可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您不能使用 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.
技术不同,但对上一个问题的回答 对整个 HTTP 交换有很好的描述。该答案中提到的策略之一是让您的操作在幕后将帖子发布到第三方网站,然后重定向到适当的位置。这可以通过 HttpClient 或 HttpURLConnection 而不是 .NET HttpWebRequest 来完成。
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.