Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the anchor name in HTTP GET?

Tags:

java

servlets

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&param2=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&param2=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.

like image 674
jbatista Avatar asked Jul 19 '11 10:07

jbatista


1 Answers

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
like image 115
Jacob Avatar answered Oct 19 '22 05:10

Jacob