Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在浏览器上查看数据_Java_Url_Grails_Urlconnection - Fatal编程技术网

Java 在浏览器上查看数据

Java 在浏览器上查看数据,java,url,grails,urlconnection,Java,Url,Grails,Urlconnection,我有一个域,其中包含URL、lastModified等字段。现在我想在列表页面中查看我从该代码中获得的信息。我怎么做 def url = new URL("http://www.google.com") HttpURLConnection connection = (HttpURLConnection)url.openConnection() // long contentLength = Long.parseLong(connection.getHeaderField("Content-Le

我有一个域,其中包含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"
}

从控制器中,可以使用
渲染
方法

render returnMessage
(见附件)

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

return [returnMsg: returnMessage]

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

(请参见)

在哪里?在一页中?你的问题有点含糊。请提供更多关于环境的细节。我的意思是,我现在得到了这个println东西,jst来检查它是否工作。现在我想在grailslist.gsp页面中填充这些信息