How do I get URL label when parsing request URL?

2019-01-27 21:50发布

URL can have a label, separated with a "#" sign, coming after the URL parameters. E.g. http://example.com/foo/bar.jsp?p1=v1#test_label

I would expect label to be part of request.getQueryString() and part of request.getRequestURL().toString(). But it doesn't seem to be there.

Is there a way to retrieve the label value from HttpServletRequest on server side?

1条回答
唯我独甜
2楼-- · 2019-01-27 22:23

I think the HTTP spec decided that "anchors" (Is that what they're called? Anyway, the hash sign and the label that comes after) don't get passed to the server, they're just used client-side to scroll the page, or to be used in JavaScript. So there's no way you can get that value, other than having a little script passing it to your server with an Ajax request once the page is loaded, but that's not very convenient.

查看更多
登录 后发表回答