4

I need to get all parameters from the request including what comes after "#". example: request: http://myserver/m#q=abc I need my server to get all parameters after "#" as they where after "?" How can i do that? 10x, Koby

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
koby
  • 665
  • 2
  • 6
  • 15

3 Answers3

11

Anchors or URL fragments as they are referred to in RFC 1738, are not sent by the client to the server, when requesting for a resource. The rationale is that fragment URLs are utilized to identify a location within a resource and not a different resource on the server. In order to identify the location in the resource, the client needs to fetch the complete resource from the server, and this process need not involve transfer of information about the fragment (as it does not mean anything to the server).

If you do wish to submit information via the query string using a URL containing a fragment, you will have to ensure that the querystring precedes the URL fragment. This might be a bug in your client-side code, if you're constructing the request on your own. Leave the request construction logic to the browser, if you can afford to do so.

If you do wish to send the fragment character (#) to the server, then you'll need to encode it in the query string, or the client(browser) will simply ignore that section of the URL when it sends the request to the server.

Related Questions on SO

  1. JSP Servlet anchor
  2. How to obtain anchor part of URL after # in php
Community
  • 1
  • 1
Vineet Reynolds
  • 76,006
  • 17
  • 150
  • 174
2

Have in mind that anchors are a client-side concept so they shouldn't be used in the server side. Clients don't send the anchor data to the server, so you can't do this. Better use get parameters.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • request.getRequestURI() returns "m", without the q=abc request.getQueryString() returns null... – koby Nov 25 '10 at 11:10
  • Are you sure it is not sent to the server? any documentation about it? If that is for sure i can redirect on javascript and replace the "#" with a "?", but i prefer to do it without redirect(for SEO reasons). – koby Nov 25 '10 at 11:19
  • I am curious about the case when you bookmarked a site say http://xyz.com#fragment : then xyz.com redirects to an SSO site, where the user signs in and will be redirected to http://xyz.com since the #fragment was never sent to the SSO service (it might have received in its query string or POST parameters something like requestingApp=http%3A%2F%2Fxyz.com) – Ustaman Sangat May 10 '13 at 22:20
  • well, yes, you lose the anchor. Not much you can do about it. – Bozho May 11 '13 at 10:15
1

You can't do this. The URI spec says:

A reference to a particular part of a document may, including the fragment identifier, look like

http://www.myu.edu/org/admin/people#andy

in which case the string "#andy" is not sent to the server, but is retained by the client and used when the whole object had been retrieved.

alex
  • 479,566
  • 201
  • 878
  • 984
Paul M
  • 357
  • 1
  • 8