【发布时间】:2008-10-28 01:25:01
【问题描述】:
如何将 Groovlet 放入 Grails 应用程序?比如说,在 web-app/groovlet.groovy 中
导入 java.util.Date 如果(会话 == null){ 会话 = request.getSession(true); } if (session.counter == null) { session.counter = 1 } 打印""""""
【问题讨论】:
如何将 Groovlet 放入 Grails 应用程序?比如说,在 web-app/groovlet.groovy 中
导入 java.util.Date 如果(会话 == null){ 会话 = request.getSession(true); } if (session.counter == null) { session.counter = 1 } 打印"""【问题讨论】:
grails install-templatessrc/templates/web/web.xml 以包含您的 groovletgrails war我没有亲自这样做来合并 groovlet,但这是修改已部署 Grails web.xml
【讨论】:
按照我的理解,当你有一个支持 Groovy 脚本的 Servlet 容器时使用 groovlet,
我认为在 Grails 中,您需要将业务逻辑代码移至 controller,并将视图部分保留为 HTML 或 GSP file。
类似的东西(我头脑中的元代码,未经测试):
grails-app/controllers/SampleController.groovy
class DateController {
def index = {
if (session == null) {
session = request.getSession(true);
}
if (session.counter == null) {
session.counter = 1
}
}
}
web-app/sample/index.gsp
<html>
<head>
<title>Groovy Servlet</title>
</head>
<body>
Hello, ${request.remoteHost}: Counter: ${session.counter}! Date: ${new Date()}
<br>
希望有帮助!
【讨论】: