嵌套 HTTP GET 参数(请求中的请求)

发布于 2024-12-08 19:57:18 字数 884 浏览 2 评论 0原文

我想在父 JSP 的 GET 参数内调用带有 GET 参数的 JSP。其 URL 为 http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90

getName.jsp 将返回一个字符串,该字符串位于 getMap.jspname 参数中。

我认为这里的问题是 URL 末尾的 &lon1=-90 将被赋予 getMap.jsp 而不是 getName.jsp代码>. 有没有办法区分哪个 GET 参数指向哪个 URL?

我的一个想法是对第二个 URL 进行编码(例如 = -> %3D< /code> 和 & -> %26) 但这效果不佳。到目前为止,我最好的想法是在第二个 URL 中只允许一个参数,以逗号分隔。所以我会有 http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?params=30,-90 和让 getName.jsp 来解析其变量。这样我就不用管 & 了。

注意 - 我知道我可以从一个完全不同的角度解决这个问题,并完全避免嵌套 URL,但我仍然想知道(为了知识!)这是否可能或是否有人已经做到了。 ..

I want to call a JSP with GET parameters within the GET parameter of a parent JSP. The URL for this would be http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90

getName.jsp will return a string that goes in the name parameter of getMap.jsp.

I think the problem here is that &lon1=-90 at the end of the URL will be given to getMap.jsp instead of getName.jsp. Is there a way to distinguish which GET parameter goes to which URL?

One idea I had was to encode the second URL (e.g. = -> %3D and & -> %26) but that didn't work out well. My best idea so far is to allow only one parameter in the second URL, comma-delimited. So I'll have http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?params=30,-90 and leave it up to getName.jsp to parse its variables. This way I leave the & alone.

NOTE - I know I can approach this problem from a completely different angle and avoid nested URLs altogether, but I still wonder (for the sake of knowledge!) if this is possible or if anyone has done it...

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

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

发布评论

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

评论(1

趁年轻赶紧闹 2024-12-15 19:57:18

这已经做了很多,特别是在广告服务技术和 URL 重定向方面

,但编码的 URL 应该可以正常工作。您需要对其进行完全编码。可以在此处找到生成器

,因此:
http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90

变为这个:http://server/getMap.jsp?lat=30&lon=-90&name=http%3A%2F%2Fserver%2FgetName.jsp%3Flat1%3D30%26lon1%3D-90

我确信jsp有这个功能。寻找“urlencode”。您的 JSP 会将 GET 变量“名称”的内容视为未编码的字符串:“http://server/getName.jsp?lat1=30&lon1=-90”

This has been done a lot, especially with ad serving technologies and URL redirects

But an encoded URL should just work fine. You need to completely encode it tho. A generator can be found here

So this:
http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90

becomes this: http://server/getMap.jsp?lat=30&lon=-90&name=http%3A%2F%2Fserver%2FgetName.jsp%3Flat1%3D30%26lon1%3D-90

I am sure that jsp has a function for this. Look for "urlencode". Your JSP will see the contents of the GET-Variable "name" as the unencoded string: "http://server/getName.jsp?lat1=30&lon1=-90"

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