我创建使用JSF,休眠,春天的Web应用程序。我添加了检查会话的过滤器。我的滤波代码为:的Java FilterImplementation会话检查
public class AdminFilter implements Filter{
private ArrayList<String> urlList;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
String urls = filterConfig.getInitParameter("avoid-urls");
StringTokenizer token = new StringTokenizer(urls, ",");
urlList = new ArrayList<String>();
while (token.hasMoreTokens()) {
urlList.add(token.nextToken());
}
}
// Checking if user is logged in
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req= (HttpServletRequest) request;
HttpServletResponse resp= (HttpServletResponse) response;
String url = req.getServletPath();
HttpSession session = req.getSession();
if(!urlList.contains(url) && session.getAttribute("user")==null)
{
resp.sendRedirect(req.getContextPath() + "/backend/login/index.xhtml");
}
chain.doFilter(req, resp);
}
@Override
public void destroy() {
// throw new UnsupportedOperationException("Not supported yet.");
}
}
在过滤器的init方法我有哪个会话检查应该被跳过,像登录页面本身的一些避免URL。这是工作正确的,但这个过滤器限制我的CSS,图像和JS载入登录页面。 建议我什么是我的过滤器的问题?
跳过JS,CSS?,它应该是像'/ PATH/TO/CSS/FROM/WEBROOT/CSS /' –
你有CSS,JS,Images的任何参数吗?(正在使用登录页面)? –