java - 如何在 HTTP GET 中获取 anchor 名称?

标签 java servlets

在 Java web 项目中,如何获取(如果可能)URL 请求中的“HTTP anchor ”部分? 例如,当请求 URL 为 http://localhost:8080/servlet/page.htm?param1=value1&param2=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/

相关文章:

java - 优化 SSE 代码

apache - 配置 Tomcat 以利用浏览器缓存?

tomcat - web.xml 中的多个安全约束不起作用

java - 如何在 Camel 中实现路由性能测量

java - Singleton的其他成员

java - Firebase setValue 与不同类型的 Map

Java 8 流和可变参数

java - 上传中保存文件的路径我真的应该选择 getServletContext 吗?

javascript - JSP:如何将下拉列表的所有(选中和未选中)选项传递给 servlet?

java - 如何处理一个823237个字符的字符串