Java 在浏览器上查看数据
我有一个域,其中包含URL、lastModified等字段。现在我想在列表页面中查看我从该代码中获得的信息。我怎么做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
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页面中填充这些信息