我正在尝试在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)
答案 0 :(得分:1)
试试这个
def user = session?.user
if (user) {
out << "Hello ${session.user.login} "
out << """[${link(action:"logout",controller:"user"){"Logout"}}]"""
}
答案 1 :(得分:0)
我认为, reuqest.getSession(false)必须有效。 由于grails documentation:
请求对象是Servlet API的HttpServletRequest类的实例
HttpServletRequest
中的公共HttpSession getSession(boolean create);通过日志,我们可以看到, org.apache.catalina.connector.RequestFacade 还有 getSession(boolean)
在我看来,你有一些插件或库的麻烦。