日期:2014-05-18  浏览次数:20715 次

关于Filter中url-pattern的简单问题
就是简单的判断session值的问题,如果session为空,则跳转到login.do

但是web.xml中应该如何配置?

登录页面的路径和其他页面的路径在同一个路径下面:
http://localhost:8080/project/...

这样似乎不行啊,因为每次跳转到login.do之后,又自动执行了一次filter,这样不断进入死循环了!

有没有办法来改正一下?

doFilter代码如下
Java code

        String userId = (String)httpServletRequest.getSession().getAttribute("userId");
        
        try{
            if(userId != null){               
                filterChain.doFilter(request, response);
            }
            else{
                httpServletResponse.sendRedirect("http://localhost:8080/Medinet/login.do");
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }



------解决方案--------------------
权限filter的模型是需要有配置过滤list和非过滤list这样的属性配置~~~。你可以参考网上很多的权限filter来实现你的。