如何在Grails中使用过滤器

5

我有一个过滤器,希望能过滤掉除了一个可将我带到登录页面的操作之外的所有操作。
如果我用某些条件过滤所有页面,那么甚至登录页面也会被过滤掉,因此它会陷入无限循环,因为条件不满足(用户未登录)。 session.getAttribute("CurrentEmployeeIds") 它告诉我们用户是否已登录。


我的过滤器如下:

class LoginFilters {

    def filters = {
        all(controller:'dashboard', action:'*') {
            before = {
                if (session.getAttribute("CurrentEmployeeIds")==null) {
                    redirect(controller:"site",action:"index")
                    return false
                }
            }
            after = { Map model ->

            }
            afterView = { Exception e ->

            }
        }
    }
}

我希望通过筛选的方式来过滤URL,使得其不会过滤controller:"site",action:"index"这个URL,但是过滤其他所有内容。
先行致谢。

1
你可以通过 actionNamecontrollerName 获取动作和控制器的名称,并在简单的 if 语句中进行检查。你可以针对特定的动作返回 true - Alidad
1
这与Struts 2有何关系? - Dave Newton
1个回答

12

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接