How to get the URL fragment identifier from HttpServletRequest
Asked Answered
S

2

17

How do I get the URL fragment identifier from HttpServletRequest?

The javadocs doesn't seem to mention it.

Searles answered 21/11, 2012 at 22:38 Comment(0)
H
24

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.

Hallucinatory answered 21/11, 2012 at 22:41 Comment(0)
J
-1

Take a look at the following link: https://www.rfc-editor.org/rfc/rfc2396

Jilolo answered 21/11, 2012 at 22:42 Comment(1)
How could it help with getting the fragment from http request?Ligule

© 2022 - 2024 — McMap. All rights reserved.