I’m trying to redirect my response but I got stuck at the link path.
The following command takes me to the tomcat’s localhost and searches for the page there but it can’t find anything, as expected.
response.sendRedirect("/myPage.html");
In order to manage this problem I have to put my root folder name (the one from webaps) in the link path, but I don’t think that’s a really good idea.
response.sendRedirect("/mySite/myPage.html");
Why is this happening? Is there any other way to solve this problem, besides getRequestURL() or something like that?
A relative redirect URL is relative to the current request URL (the one as you see in the browser address bar). The leading
/will take you to the domain root. The behaviour is perfectly predictable and normal. If themyPage.htmlis in the same folder as the current request URL, then you can just remove the leading/:Or if that is never reliably predictable because the current request URL can come from anywhere in your webapp, then just dynamically include the context path: