我想更改请求uri /aaa/bbb/ccc
至 /bbb/ccc
. 换句话说,我想删除请求uri的第一部分。
我试着使用下面的过滤器,但它不工作。
public class AnyRequestHandlerFilter implements Filter, Ordered {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
System.out.println(httpRequest.getRequestURI());
String path = httpRequest.getRequestURI();
if (path.contains("/aaa")) {
log.info("front:{}", path);
path = path.replace("/aaa/", "/");
log.info("back:{}", path);
httpRequest.getRequestDispatcher(path).forward(httpRequest, servletResponse);
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
}
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!