How do I get URL label when parsing request URL?

2019-01-27 22:10发布

问题:

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:

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.