Filter过滤器,过滤后登陆界面无法正常跳转,好像一直重定向到登陆界面,就大神看看

这是我Filter的代码

public class FilterServlet extends HttpServlet implements Filter {
private FilterConfig config;
public void init(FilterConfig config) throws ServletException {
// TODO Auto-generated method stub

    this.config=config;
    System.out.print("过滤器已执行");
}

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    // TODO Auto-generated method stub
    //获取Filter的配置参数
    String loginpage= config.getInitParameter("loginpage");
    HttpServletRequest req = (HttpServletRequest) request;
    String requestPath = req.getServletPath();

    //StringBuffer fileURL = req.getRequestURL();
    // 存储上下文路径
    request.setAttribute("path", req.getContextPath());

    if(!requestPath.endsWith(loginpage)){


             // 跳转到登录页面
            request.getRequestDispatcher(loginpage)
        .forward(request, response);
    }else{
            chain.doFilter(request, response);

}
}


/**
 * Constructor of the object.
 */
public FilterServlet() {
    super();
}

/**
 * Destruction of the servlet. <br>
 */
public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    this.config = null;
}

public void init() throws ServletException {
    // TODO Auto-generated method stub

}
}

下面是我再web.xml文件中配置的Filter
pathfilter
com.personnel.filter.FilterServlet

loginpage
/login.jsp



pathfilter
<!-- struts2匹配根路径下的全部请求,拦截所以用户请求 ,在日志中简要记录请求的信息-->
/*

我只要把if的内容注释掉就能正常跳转,但是过滤功能无法实现,如上代码的过滤功能能够实现,无法点开除login.jsp以外的界面 ,但是按登录按钮无法进行正常的跳转,一直重定向为登录界面,求大神解答

 通过你的if判断,现在把不是链接到登陆页面的链接全都换成了到登陆页面,要过滤的话通过session拦截未登录的就行了


pathfilter
com.personnel.filter.FilterServlet

loginpage
/login.jsp



pathfilter
<!-- struts2匹配根路径下的全部请求,拦截所以用户请求 ,在日志中简要记录请求的信息-->
/*

web.xml配置是这样的

一般都是登录成功后,将当前用户信息放入session,然后拦截所有url,透过判断session中的用户是否为空以及是否有权限来判断是否放行