如何从 HttpServletRequest 获取 URL 片段标识符

编程入门 行业动态 更新时间:2024-10-23 19:27:04
本文介绍了如何从 HttpServletRequest 获取 URL 片段标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何从 HttpServletRequest 获取 URL 片段标识符?

How do I get the URL fragment identifier from HttpServletRequest?

javadocs 似乎没有提及.

推荐答案

您无法以您想要的方式获取 URL 片段.

You can't get the URL fragment in the way you'd like.

通常,浏览器不会将片段发送到服务器.这可以通过使用网络协议分析器如 tcpdump、Ethereal、Wireshark、Charles.

Typically, the browser doesn't send the fragment to the server. This can be verified by using a network protocol analyser like tcpdump, Ethereal, Wireshark, Charles.

但是,您可以在 JavaScript 请求中将片段字符串作为 GET/POST 参数发送.要使用 JavaScript 获取值,请使用 window.location.hash.然后,您可以在 AJAX 请求中将此值作为 GET 或 POST 参数传递,并使用 HttpServletRequest 上的 getParameter 方法进行 AJAX 请求.

However, you can send the fragment string as a GET/POST parameter on a JavaScript request. To get the value using JavaScript, use window.location.hash. You can then pass this value as a GET or POST parameter in an AJAX request, and use the getParameter methods on the HttpServletRequest for the AJAX request.

这里是 RFC3986:统一资源标识符 (URI):通用语法 不得不说:

片段标识符是分开的从取消引用之前的 URI 的其余部分,因此片段本身内的识别信息被取消引用完全由用户代理,无论 URI 方案如何.虽然这种单独的处理通常被认为是损失信息,特别是用于准确重定向引用作为资源随时间移动,它也有助于防止信息提供者拒绝参考作者引用的权利资源中的信息有选择地.间接引用也为使用的系统提供额外的灵活性和可扩展性URI,因为新媒体类​​型比新媒体类型更容易定义和部署识别方案.

The fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent, regardless of the URI scheme. Although this separate handling is often perceived to be a loss of information, particularly for accurate redirection of references as resources move over time, it also serves to prevent information providers from denying reference authors the right to refer to information within a resource selectively. Indirect referencing also provides additional flexibility and extensibility to systems that use URIs, as new media types are easier to define and deploy than new schemes of identification.

更多推荐

如何从 HttpServletRequest 获取 URL 片段标识符

本文发布于:2023-10-12 23:25:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486184.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   片段   HttpServletRequest   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!