java获取url锚点_java – 从URI获取锚点

这是不可能的,因为客户端不会将“锚定部分”发送到服务器

举个例子,以下是提交http://example.com/#foobar(使用Wireshark记录)后Chrome生成的确切要求:

GET / HTTP/1.1

Host: example.com

Connection: keep-alive

User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.223.11 Safari/532.3

Cache-Control: max-age=0

Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Encoding: gzip,deflate

Accept-Language: en-US,en;q=0.8

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

If-None-Match: "b300b4-1b6-4059a80bfd280"

If-Modified-Since: Tue, 15 Nov 2005 13:24:10 GMT

请参见no #foobar.所以服务器应用程序无法读取它.

你可以做一些JavaScript的魔术,将锚点存储在cookie或隐藏的输入域中,或者是你进入的任何巫术.但是,对于不是源自您自己的站点的请求,它不会有效.在查询字符串的服务器部分进行所需的任何操作都比较简单,并且仅使用锚定到JavaScript的任务,或者使用它来在一个简单的HTML文档中导航,但这就是90s;).

以下是RFC 1808的重要部分:

Note that the fragment identifier (and the “#” that precedes it) is not considered part of the URL. However, since it is commonly used within the same string context as a URL, a parser must be able to recognize the fragment when it is present and set it aside as part of the parsing process.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值