我有一个URLRewriteFilter,它检查请求的域名是否以www开头,并重定向到非www网址。当请求需要重定向时,如何停止进一步处理(调用JSF应用程序、调用servlet等)?
目前我有以下代码:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String sn = req.getServerName().toLowerCase();
if (sn.startsWith("www.")) {
String url = "http://" + getDefaultDomain() + req.getContextPath() + req.getRequestURI();
HttpServletResponse resp = (HttpServletResponse) response;
resp.reset();
resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
resp.setHeader("Location", url);
}
chain.doFilter(request, response);
}
chain.doFilter
。 - OrangeDog