How to get the URL fragment identifier from HttpServletRequest

后端 未结 2 1051
半阙折子戏
半阙折子戏 2020-11-30 11:27

How do I get the URL fragment identifier from HttpServletRequest?

The javadocs doesn\'t seem to mention it.

相关标签:
2条回答
  • 2020-11-30 12:04

    Take a look at the following link: http://tools.ietf.org/html/rfc2396

    0 讨论(0)
  • 2020-11-30 12:19

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

    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.

    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.

    Here's what RFC3986: Uniform Resource Identifier (URI): Generic Syntax has to say:

    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.

    0 讨论(0)
提交回复
热议问题