gpt4 book ai didi

session - grails在 session 中保留许多页面

转载 作者:行者123 更新时间:2023-12-02 15:10:34 25 4
gpt4 key购买 nike

我是新来的。我最近在 Controller 中使用了 session 。但是只有一页。现在,我想在多个页面上使用 session 。但是我不知道该怎么做。这是我的下面的代码,适用于一页。有人可以帮我吗?

def index() {
def user = springSecurityService.currentUser
if (user){
redirect(controller: 'admistratorAction', action: 'createUser')
}else{
redirect(controller: 'login', action: 'index')
}

}

最佳答案

您可能是Grails的新手,但愿您不是HttpSession的新手。 :)

Session information is scoped only to the current web application (ServletContext), so information stored in one context will not be directly visible in another.



只要您使用的是 ServletContext,您就应该可以直接访问 session 变量。也请看grails中的 Servlet API

@ Alidad-滚动回OP中的最后一个问题。

关于session - grails在 session 中保留许多页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com