我正在尝试在GSP中使用Groovy函数。 我的GSP顶部有<%@ page import = company.ConstantsFile %>
。
在我的GSP中,我有:
<p>
I have been in the heating and cooling business for <%(ConstantsFile.daysBetween())%>
</p>
以及我的 ConstantsFile.groovy
package company
import static java.util.Calendar.*
class ConstantsFile {
def daysBetween() {
def startDate = Calendar.instance
def m = [:]
m[YEAR] = 2004
m[MONTH] = "JUNE"
m[DATE] = 26
startDate.set(m)
def today = Calendar.instance
render today - startDate
}
}
我也尝试过将renter更改为puts、system.out等,但这不是我的主要问题。
Error 500: Internal Server Error
URI
/company/
Class
java.lang.NullPointerException
Message
Cannot invoke method daysBetween() on null object
所以我尝试一下
<p>
I have been in the heating and cooling business for <%(new ConstantsFile.daysBetween())%>
</p>
但是我遇到了问题
Class: org.codehaus.groovy.control.MultipleCompilationErrorsException
unable to resolve class ConstantsFile.daysBetween @ line 37, column 1. (new ConstantsFile.daysBetween()) ^ 1 error
请帮我或指向一个网站,展示应该怎么做。我试过谷歌搜索了,但所有的文章都涉及到 g:select 或其他类型的标签... 我只想像在 JSPs 里一样输出函数结果。