[Grails] 在Grails中如何配置过滤器?我找不到web.xml!

zengsun 2007-12-07
这个论坛的人气真是差呀。3天都没有人回帖!!!
coldrush 2013-02-04
像下面的代码一样,定义个文件***Filters.groovy放到conf文件夹就自动配置了一个过滤器,用不着去web.xml

import grails.converters.JSON

class LogFilters {


    def grailsApplication

    def filters = {
        logAll(controller: '*', action: '*') {
            before = {

                //-------------------------如果用户登录-------------------------

                def footprintTrackOn = grailsApplication.config.footprintTrackOn

                if (footprintTrackOn) {
                    def json = [
                            ip: request.getRemoteAddr(),
                            ua: request.getHeader("User-Agent"),
                            controller: controllerName,
                            action: actionName,
                            uid: session.userId ?: "0",
                            ut: session.userType ?: 0,
                            time: new Date().format("yyyy/MM/dd HH:mm:ss"),
                            params: params.toString()
                    ] as JSON

                    rabbitSend 'fpq', json.toString()
                }

            }
            after = { Map model ->


            }
            afterView = { Exception e ->

            }
        }
    }
}

Global site tag (gtag.js) - Google Analytics