How are you getting your uri value? what is it's value? I suspect it might be "/my-app/xxx/test/bat". When you use request.getRequestDispatcher if the path begins with a "/" it is interpreted as relative to the current context root.
URI rewriting add unwanted context path
-
11-04-2022 - |
Question
I have my app to find resource at
http://myhost/my-app/test/bat
and it works good, now have this a new request to
http://myhost/my-app/xxx/test/bat,
I simply want it rewrited to the old one, so I creat a filter:
if(uri.endsWith("/xxx/test/bat")){ uri=uri.replace("/xxx/test", "/test"); request.getRequestDispatcher(uri).forward(req, res); } else chain.doFilter(req, res);
but the tomcat container rewrite the url to:
http://myhost/my-app/my-app/test/bat
/my-app is the contextPath
why I got this extra my-app? where did I go wrong?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow