我正在JSF應用程序中實現登錄過濾器。我有一個私人領域稱爲配置。儘管在init和destroy方法中引用了該字段,但Eclipse會顯示警告「字段AuthenticationFilter.config的值未使用」。我在這裏做錯了什麼,或者是Eclipse有點困惑?Eclipse中的字段未使用警告
這裏的AuthenticationFilter類:
package com.mymato.coop;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebFilter("/restricted/*")
public class AuthenticationFilter implements Filter {
private FilterConfig config;
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
if (((HttpServletRequest) req).getSession().getAttribute(
LoginBean.AUTH_KEY) == null) {
((HttpServletResponse) resp).sendRedirect("../login.xhtml");
} else {
chain.doFilter(req, resp);
}
}
public void init(FilterConfig config) throws ServletException {
this.config = config;
}
public void destroy() {
config = null;
}
}