How to get the anchor name in HTTP GET?

六月ゝ 毕业季﹏ 提交于 2019-12-30 09:46:07

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/6745993/how-to-get-the-anchor-name-in-http-get

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!