【问题标题】:JSF filter not executed未执行 JSF 过滤器
【发布时间】:2013-01-05 23:14:21
【问题描述】:
@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 中没有条目,都是基于 Annotations。

【问题讨论】:

  • 您从哪里获得过滤器模板?所有那些UnsupportedOperationExceptions 都是完全错误的。然而,我记得以前看过几次。也许您在网站或书中的某个地方找到了它。如果有,是哪一个?
  • 真的吗?哇。因此,它不仅会生成 servlet,其 doPost()doGet() 委托给完全相同的 processRequest() 方法,这是完全错误的,而且还会生成这样的损坏过滤器?
  • 当您希望netbeans 实现所有接口方法时,它的默认代码是sn-p。它可能可以在 NB 选项中更改,但它是默认值。
  • 在Eclipse中,我只需要右键包,NewFilter,指定类名就可以了。
  • 他们很愚蠢。就像他们只想放置会导致问题的代码,并将其隐藏在抛出 RuntimeException 中只是为了支持您不会看到任何编译器错误。

标签: jsf servlet-filters


【解决方案1】:

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

【讨论】:

  • 哈哈,这很聪明:D。谢谢。
猜你喜欢
  • 2014-12-12
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 2013-06-02
  • 2020-08-04
  • 1970-01-01
  • 2015-05-10
相关资源
最近更新 更多