java 如何从 HttpServletRequest 获取 URL 片段标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13503213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the URL fragment identifier from HttpServletRequest
提问by Kurru
回答by Martin Ellis
You can't get the URL fragment in the way you'd like.
您无法以您想要的方式获取 URL 片段。
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.
通常,浏览器不会将片段发送到服务器。这可以通过使用网络协议分析器(如 tcpdump、Ethereal、Wireshark、Charles)来验证。
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.
但是,您可以在 JavaScript 请求中将片段字符串作为 GET/POST 参数发送。要使用 JavaScript 获取值,请使用window.location.hash
. 然后,您可以在 AJAX 请求中将此值作为 GET 或 POST 参数传递,并使用 HttpServletRequest 上的 getParameter 方法来处理 AJAX 请求。
Here's what RFC3986: Uniform Resource Identifier (URI): Generic Syntaxhas to say:
以下是RFC3986: Uniform Resource Identifier (URI): Generic Syntax必须说的内容:
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.
在取消引用之前,片段标识符与 URI 的其余部分分开,因此片段本身中的标识信息仅由用户代理取消引用,而不管 URI 方案如何。尽管这种单独的处理通常被认为是信息的丢失,尤其是在资源随时间移动时准确重定向参考文献,但它也有助于防止信息提供者拒绝参考作者有选择地参考资源中的信息的权利。间接引用还为使用 URI 的系统提供了额外的灵活性和可扩展性,因为新的媒体类型比新的标识方案更容易定义和部署。
回答by Nick Robertson
Take a look at the following link: http://tools.ietf.org/html/rfc2396
看看下面的链接:http: //tools.ietf.org/html/rfc2396