【发布时间】: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中,我只需要右键包,New,Filter,指定类名就可以了。
-
他们很愚蠢。就像他们只想放置会导致问题的代码,并将其隐藏在抛出
RuntimeException中只是为了支持您不会看到任何编译器错误。
标签: jsf servlet-filters