如何从 HttpServletRequest 获取 URL 片段标识符 [英] How to get the URL fragment identifier from HttpServletRequest

查看:42
本文介绍了如何从 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、EtherealWiresharkCharles.

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 片段标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆