0
@WebFilter(filterName = "loginFilter",  value = { "/faces/kosz.xhtml" } , dispatcherTypes = { DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.REQUEST, DispatcherType.INCLUDE }  )
public class loginFilter implements Filter {    
    public loginFilter(){
    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
            throws IOException, ServletException{
        HttpServletRequest req = ( HttpServletRequest ) request;
        userSession auth = ( userSession ) req.getSession().getAttribute("user");
        if ( auth != null && auth.isLogged() ) {
            chain.doFilter(request, response);
             HttpServletResponse res = ( HttpServletResponse ) response;
            res.sendRedirect(req.getContextPath() + "/login.xhtml");
        }
        else {
            HttpServletResponse res = ( HttpServletResponse ) response;
            res.sendRedirect(req.getContextPath() + "/login.xhtml");
        }
      }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }

    @Override
    public void destroy()
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }
/**
 * Return the filter configuration object for this filter.
}

问题是过滤器没有执行。网址是localhost:8080/PP2/faces/kosz.xhtml。这样做的正确方法是什么?我的 web.xml 中没有条目,它都是基于注释的。

4

1 回答 1

4

init()您在过滤器和destroy()方法中抛出异常。如果您不想在init()or中做任何事情destroy(),只需将方法体留空即可。在这种情况下,您的过滤器根本没有成功初始化。

于 2013-01-22T16:38:29.937 回答