gpt4 book ai didi

grails - 在Grails的TagLib中使用request.getSession(false)会引发异常

转载 作者:行者123 更新时间:2023-12-02 15:29:00 24 4
gpt4 key购买 nike

我试图在Grails 2.3.5的TagLib中使用以下代码。

class LoginTagLib {
def loginControl = {
if(request.getSession(false) && session.user){
out << "Hello ${session.user.login} "
out << """[${link(action:"logout",controller:"user"){"Logout"}}]"""
}
else {
out << """[${link(action:"login",
controller:"user"){"Login"}}]"""
}
}

}

我收到以下错误:
groovy.lang.MissingMethodException: No signature of method: org.apache.catalina.connector.RequestFacade.session() is applicable for argument types: (java.lang.Boolean) values: [false]
Possible solutions: getSession(boolean), getSession()
racetrack.LoginTagLib$_closure1.doCall(LoginTagLib.groovy:9)
D__JAVA_GRAILS_WORKSPACE_RaceTrack_grails_app_views_layouts__header_gsp.run(_header.gsp:7)
D__JAVA_GRAILS_WORKSPACE_RaceTrack_grails_app_views_layouts_main_gsp$_run_closure2.doCall(main.gsp:22)
D__JAVA_GRAILS_WORKSPACE_RaceTrack_grails_app_views_layouts_main_gsp.run(main.gsp:25)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)

最佳答案

试试这个

def user = session?.user

if (user) {
out << "Hello ${session.user.login} "
out << """[${link(action:"logout",controller:"user"){"Logout"}}]"""
}

关于grails - 在Grails的TagLib中使用request.getSession(false)会引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23240703/

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