After checking the condition if the condition fails then using request dispatcher iam redirecting it to some other page.It is redirecting to that page but the css is not applying to that page.Why is it so?
public class RolePrivilegeFilter implements Filter {
List<String> privilege = null;
private static final String notAuthorizedPath = "/home/notAuthorized.jsf";
@Override
public void destroy() {
log.info("filter finish");
}
@Override
public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain filterChain) throws IOException, ServletException {
String smUser = null;
try {
HttpServletRequest request = (HttpServletRequest) sRequest;
HttpServletResponse response = (HttpServletResponse) sResponse;
HttpSession session = null;
try {
request = (HttpServletRequest) sRequest;
smUser = request.getHeader(EnvironmentBean.SESSION_ATTR_SM_USER);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
if (rolePrivilege == null || rolePrivilege.isEmpty()) {
rolePrivilege = new RolePrivilegeBuilderImpl().rolePrivilege("Smtest2");
privilege filter bean is\t"+rolePrivilege);
log.debug("After rolePrivilege: " + rolePrivilege);
if (rolePrivilege != null && rolePrivilege.size() > 0 ) {
if (session == null) {
session = request.getSession(true);
}
session.setAttribute("privilege", rolePrivilege);
} else {
//This is the page iam redirecting to.
System.out.println("role privilege not authorized page");
RequestDispatcher rd = request.getRequestDispatcher(notAuthorizedPath);
rd.forward(request, response);
return;
}
} catch (Exception e) {
e.printStackTrace();
log.debug("Error in setting session attribute: " + e.getMessage());
}
log.debug("doFilter() finish");
filterChain.doFilter(sRequest, sResponse);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
log.info("filter start");
}
}
The problem is iam redirecting to that page but the css to that page is not being applied like background image not getting displayed.Why is it so?
Apparently the filter’s URL pattern did also match the browser’s request for that CSS file and thus it has also been blocked by the filter. Apparently you’ve mapped the filter on a too broad URL pattern like as
/*or something.You need to ensure that the filter bypasses all those CSS file requests. If there’s no way to change the filter’s URL pattern accordingly so that it bypasses CSS file requests, e.g. changing
/*to/app/*so that it only runs on requests in/appfolder where all restricted resources are, then you need to rewrite the filter’s code to add an extra check on the request URI.Something like this:
This will let all
*.cssrequests be passed instead of being blocked.