I’m trying to forward a request to another URL which includes the hash symbol (‘#’):
request.getRequestDispatcher("/some/path.jsp#somehash").forward(request, response);
Tomcat, however, tells me that “the requested resource is not available”. If I remove the hash from the URL, everything works fine. Are hashes not allowed or am I not treating them right?
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.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.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.