在 Java web 项目中,如何获取(如果可能)URL 请求中的“HTTP anchor ”部分?
例如,当请求 URL 为 http://localhost:8080/servlet/page.htm?param1=value1¶m2=value2#section 时我希望能够识别 #section
部分。
public void doGet
(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// ...
System.out.println("QueryString = " + request.getQueryString());
// ...
}
上面的示例生成 前面 #
的子字符串,在本例中为:param1=value1¶m2=value2
。有没有办法提取 #
符号后的 URL 部分?
如果这有用,我正在使用 Apache Click 框架。
最佳答案
我认为锚定部分没有发送到服务器。它仅由浏览器处理。也许您可以使用 JavaScript 提取它。
根据 RFC 1808 :
Note that the fragment identifier (and the "#" that precedes it) is not considered part of the URL.
来自 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
关于java - 如何在 HTTP GET 中获取 anchor 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6745993/