过滤器在有插件的情况下怎么使用?
|
xiao0556
2008-05-14
我建了一个过滤器放在grails-app/conf下
class SecurityFilters{
def filters = {
allURIs(uri:'/userManager/**') {
if(!session.user.isLoggedIn()){
redirect(action:'show',controller:"login")
return false;
}
}
}
}
结果报错 No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. 是什么原因呢? |
|
|
oksonic
2008-06-19
class SecurityFilters {
def filters = {
loginCheck(controller:'*', action:'*') {
before = {
if(!session.user && !actionName.equals('login')) {
redirect(action:'login')
return false
}
} }
}
}
加上 before 包就可以实现了,不过只能在action事件中过滤器才会有用 |
|
|
jimichan
2008-06-19
综合一下:
class SecurityFilters {
def filters = {
loginCheck(uri:'/userManager/**') {
before = {
if(!session.user && !actionName.equals('login')) {
redirect(action:'show',controller:"login")
return false
}
} }
}
}
这样应该是可以的 |
|
|
xiao0556
2008-06-20
谢谢楼上两位
|

