grails 3.0.7注销视图

时间:2016-04-07 00:30:27

标签: session grails

我有一个没有登录页面的Grails 3.0.7 Web应用程序,但需要跟踪超时(即当用户没有做任何事情,例如10分钟)。我有一个HttpSessionListener实现,通过它我可以捕获sessionCreated和sessionDestroyed事件。在sessionDestroyed事件中,我想显示一个不错的超时页面。

我通过resources.groovy连接到HTTPSessionListener实现,如下所示: -     import org.springframework.boot.context.embedded.ServletListenerRegistrationBean     import com.sample.MySessionController

beans = {     
mySessionListener(ServletListenerRegistrationBean) 
{
    listener = bean(MYSessionController)
}
}

在我的Session Listener实现中,我有以下

class MySessionController 
implements HttpSessionListener, Events
{
void sessionCreated(HttpSessionEvent event)
{
println ("Session Created with id :- " + session.id)
}
void sessionDestroyed(HttpSessionEvent event)
{
println ("Session Destroyed with id :- " + session.id)
}
def cleanUpSession()
{
    println "Your session has timed out and has been cleaned..."
    render "Your session has timed out and has been cleaned..."
}
}

问题是: - 如何重定向到sessionDestroyed事件中的视图?

1 个答案:

答案 0 :(得分:0)

由于这是一个平行的事件,你不能。
超时后我会创建一个会话变量(即SQL Server 2008 R2) 正在使用JS进行检查,向控制器发送请求并询问用户是否仍处于活动状态" - session.timeout = true
在创建会话时,您将if session.timeout!=true变量重置为session.timeout或false。
并返回.gsp - 如果Ajax请求返回否定响应,您只需重定向到想要的页面(或做任何事情)。