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.
}

問題は、フィルターが実行されないことです。URL はlocalhost:8080/PP2/faces/kosz.xhtmlです。これを行う適切な方法は何ですか?web.xml にエントリがありません。すべて注釈に基づいています。

4

1 に答える 1

4

init()およびdestroy()フィルターのメソッドで例外をスローします。init()またはで何もしたくない場合はdestroy()、メソッドの本体を空のままにしてください。この場合、フィルタはまったく初期化されていません。

于 2013-01-22T16:38:29.937 に答える