0

我有一个域,其中包含 URL、lastModified 等字段。现在我想查看从该代码获得的信息到列表页面中。我该怎么做

def url = new URL("http://www.google.com")
HttpURLConnection connection = (HttpURLConnection)url.openConnection()
//  long contentLength = Long.parseLong(connection.getHeaderField("Content-Length"));
connection.setRequestMethod("GET")
connection.connect()
connection.getURL()
println("Date: " + new Date(connection.getDate()))
println("LastModified Date:" + new Date(connection.getLastModified()))
if (connection.responseCode == 200 || connection.responseCode == 201){
    def returnMessage = connection.content

    //print out the full response
    println "${returnMessage}";
    System.out.println(connection.getURL());
} else {
    println "Error Connecting to " + url
    println "Couldn't connect to url"
}
4

1 回答 1

0

从您的控制器,您可以使用该render方法,

render returnMessage

(见http://grails.org/doc/2.0.x/ref/Controllers/render.html

或将其在模型中传递到 gsp 页面,然后从 gsp 打印,

return [returnMsg: returnMessage]

....(in .gsp)
${returnMsg}

(见http://grails.org/doc/2.0.x/guide/theWebLayer.html#GSPBasics

于 2012-07-06T04:33:31.237 回答