我創建使用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的任何參數嗎?(正在使用登錄頁面)? –