且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在带有RequestDispatcher的正向URL中使用哈希符号

更新时间:2022-05-11 04:58:15

#符号是浏览器,而不是服务器.当您在浏览器中键入带有#的URL时,浏览器不会将该部分发送到服务器.它发送不带URL的URL,然后在返回页面时跳转到命名锚.

The # symbol is a browser thing, not a server thing. When you type a URL with a # into the browser, the browser doesn't send that part to the server. It sends the URL without it, then jumps to the named anchor when it gets the page back.

当您要求容器为您获取该URL时,它对#的对待与对任何其他URL的对待都没有任何不同-它没有特殊含义,因此它寻找一个名为/some/path.jsp#somehash的JSP页面. ,当然不存在.

When you ask the container to get that URL for you, it doesn't treat the # any differently to any other URL - it has no special meaning for it, so it looks for a JSP page called /some/path.jsp#somehash, which of course doesn't exist.

您需要以某种方式在客户端上保留跳转到锚定逻辑.也许您可以在结果页面上放置一些javascript,以滚动到文档中的该点.

You'll need to keep that jump-to-anchor logic on the client somehow. Perhaps you could put some javascript on the resulting page to scroll to that point in the document.