如何在HTTP GET中获取锚点名称? [英] How to get the anchor name in HTTP GET?
问题描述
在Java Web项目中,如何获得(如果可能)URL请求中的"HTTP锚"部分?例如,当请求URL为 http://localhost:8080/servlet/page.htm?param1=value1¶m2=value2#section 我希望能够识别 #section
部分.
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());
// ...
}
上面的示例在#
之前的子字符串 中生成子字符串,在这种情况下为: param1 = value1& param2 = value2
.有没有办法提取#
符号后 的URL部分?
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?
如果有什么用,我正在使用Apache Click框架.
If this is of any use, I'm using the Apache Click framework.
推荐答案
我不认为锚点部分已发送到服务器.它仅由浏览器处理.也许您可以使用JavaScript提取它.
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.
根据 RFC 1808 :
请注意,片段标识符(及其前面的#")为不被视为URL的一部分.
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
这篇关于如何在HTTP GET中获取锚点名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!