groovlet コードサンプル
2007/10/07
groovlet
groovy
groovlet コードサンプルです。
request.getParameterを受けるときにnull値にならないようにparam関数を使用しています。
CGI Programming
がいろいろ参考になります。
import groovy.xml.MarkupBuilder
response.setContentType('text/html;charset=utf-8');
def c = param('c')
def t = param('t')
def url = param('u')
writer = new StringWriter()
builder = new MarkupBuilder(writer)
builder.p {
h1('更新')
form(action:'publish_post.groovy'){
p('内容を入力')
span('タイトル')
input(type:'text', name:'c', size:70, value:c)
br()
span('内容')
input(type:'text', name:'t', size:70, value:t)
br()
span('url')
input(type:'text', name:'u', size:70, value:url)
br()
input(type:'submit')
input(type:'button', value:'閉じる', onClick:"window.close()")
}
}
println """
<html><head>
<title></title>
</head>
<body>
<p>
${writer.toString()}
</p>
</body>
</html>
"""
def label(text) { b.span(text) }
def param(name) {
param(name, '')
}
def param(name, defValue) {
def val = request.getParameter(name)
if (val) return val else return defValue
}
response.setContentType('text/html;charset=utf-8');
def c = param('c')
def t = param('t')
def url = param('u')
writer = new StringWriter()
builder = new MarkupBuilder(writer)
builder.p {
h1('更新')
form(action:'publish_post.groovy'){
p('内容を入力')
span('タイトル')
input(type:'text', name:'c', size:70, value:c)
br()
span('内容')
input(type:'text', name:'t', size:70, value:t)
br()
span('url')
input(type:'text', name:'u', size:70, value:url)
br()
input(type:'submit')
input(type:'button', value:'閉じる', onClick:"window.close()")
}
}
println """
<html><head>
<title></title>
</head>
<body>
<p>
${writer.toString()}
</p>
</body>
</html>
"""
def label(text) { b.span(text) }
def param(name) {
param(name, '')
}
def param(name, defValue) {
def val = request.getParameter(name)
if (val) return val else return defValue
}
: