我在项目中使用 day CQ 开发过滤器时遇到问题。我的代码正在使用 requestDispatcher 的 forward 方法。但是使用 response.sendRedirect(),它不起作用。
if (servletRequest instanceof SlingHttpServletRequest) {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
String uri = httpRequest.getRequestURI();
if(uri.startsWith("/content")){
Cookie[] cookies = httpRequest.getCookies();
boolean found = false;
for (Cookie cookie : cookies) {
log.info("Cookies in filter: " + cookie.getName());
if("LtpaToken2".equals(cookie.getName())){
log.info("LTPA token found ");
found = true;
break;
}
}
if(found){
filterChain.doFilter(servletRequest, servletResponse);
}
else{
httpResponse.sendRedirect("http://www.google.com");
}
}else{
filterChain.doFilter(servletRequest, servletResponse);
}
log.info("Message URL ::"+httpRequest.getRequestURL().toString());
log.info("URI ::"+uri);
}
所以请解决我的问题,这是非常值得赞赏的。
问候纳尔西 p