我有一个maven项目,没有web.xml文件,因为到目前为止还没有必要。我有我的过滤器类,检查用户是否登录,但检查当前sessio中userAttribute“user”是否为null,如果是,则用户被重定向到登录页面。这是我的代码。
@WebFilter(urlPatterns = "/LogInSample /FrontController?command=createorder")
public class AuthenticationFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//pre-processing (ting der sker inden filteret bliver taget i brug)
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (httpRequest.getRequestURI().startsWith("/LogInSample/FrontController?command=createorder")
|| httpRequest.getRequestURI().startsWith("/customerpage")) {
HttpSession session = httpRequest.getSession();
System.out.println("inside of authentication filter");
if (session.getAttribute("user") == null) {
request.getRequestDispatcher("/login").forward(request, response);
}
}
chain.doFilter(request, response);
System.out.println("after do filter");
//post-processing comes after this command
我刚刚复制了一个我希望过滤器过滤的网址,只是为了测试它,但是它甚至没有输入doFilter方法,
我的注释是错的吗? Shoudl我创建了一个web.xml文件,并以这种方式配置注释,或者