How to use a Servlet Filter to change/rewrite an incoming URL?
Implement javax.servlet.Filter. In doFilter() method, cast the incoming ServletRequest to HttpServletRequest. Use HttpServletRequest#getRequestURI() to grab the path. Use straightforward java.lang.String methods like substring(), split(), concat() and so on to extract the part of interest and compose the new path. Use either ServletRequest#getRequestDispatcher() and then RequestDispatcher#forward() to forward the request/response to the new URL (server-side redirect, … Read more