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

编程入门 行业动态 更新时间:2024-10-23 21:32:44
本文介绍了如何从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方案如何。虽然这种单独处理通常被认为是b $ b信息的丢失,特别是对于随着时间的推移资源移动而准确重定向引用,它也有助于防止信息提供者来自拒绝参考作者有选择地在资源中引用信息的权利。间接引用为使用 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:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   片段   HttpServletRequest   URL

发布评论

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

>www.elefans.com

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