Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i read html anchor in java servlet?

Tags:

java

html

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

like image 469
koby Avatar asked Dec 09 '22 12:12

koby


2 Answers

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
like image 68
Vineet Reynolds Avatar answered Dec 21 '22 07:12

Vineet Reynolds


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.

like image 38
Bozho Avatar answered Dec 21 '22 07:12

Bozho