In a Java web project, how can I get (if possible) the "HTTP anchor" part in a URL request?
For example, when the request URL is http://localhost:8080/servlet/page.htm?param1=value1¶m2=value2#section I want to be able to recognize the #section
part.
public void doGet
(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// ...
System.out.println("QueryString = " + request.getQueryString());
// ...
}
The example above produces the substring preceeding the #
, in this case: param1=value1¶m2=value2
. Is there a way to extract the part of the URL after the #
sign?
If this is of any use, I'm using the Apache Click framework.
I don't think the anchor part is send to the server. It is only processed by the browser. Maybe you can extract it using JavaScript.
According to RFC 1808:
Note that the fragment identifier (and the "#" that precedes it) is not considered part of the URL.
From http://iwebdevel.com/2009/06/10/javascript-get-anchor-from-url/
var url=window.location;
var anchor=url.hash; //anchor with the # character
var anchor2=url.hash.substring(1); //anchor without the # character
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With