Search code examples
spring-mvcservletsquerystringparameter

HttpServletRequest getting request parameters separated by # instead of?


I am trying to get the Query String Parameters in the controller from the following URL using javax.servlet.http.HttpServletRequest object:

http://example.com:8080/OAuthClient/oauth-callback#access_token=something&expires_in=1209600&username=abcuser

It does not work because it is separated by # instead of ?

Hence it works if I change the request to http://example.com:8080/OAuthClient/oauth-callback?access_token=something&expires_in=1209600&username=abcuser

Is there a way to work around this problem? I have to make it work with # separated query parameters. which property will contain the data after oauth-callback?


Solution

  • Those aren't query parameters. They're the fragment of the URI - and that isn't sent to the server at all. It can only be used client-side.

    From RFC 3986:

    A fragment identifier component is indicated by the presence of a number sign ("#") character and terminated by the end of the URI.

    ... and (emphasis mine)

    Fragment identifiers have a special role in information retrieval systems as the primary form of client-side indirect referencing, allowing an author to specifically identify aspects of an existing resource that are only indirectly provided by the resource owner. As such, the fragment identifier is not used in the scheme-specific processing of a URI; instead, 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.