Java中怎么写HTML?
网友解答: package com.claridy.common;import java.io.BufferedReader;import java.io.InputStreamRead
package com.claridy.common;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;public class Test { public void testMain() throws Exception{ StringBuffer response = new StringBuffer(); HttpURLConnection connection = null; try { URL url = new URL("http://……"); connection = (HttpURLConnection) url.openConnection(); connection.connect(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String lines; while((lines = reader.readLine()) != null) { if(lines != null && lines.trim().length() 0) { response.append(lines.trim()); } else { continue; } } System.out.println(response.toString()); reader.close(); } catch(Exception e) { throw e; } finally { if(connection != null) { connection.disconnect(); } } }}
上面是 源码,这个比较简单,下面是图片显示:
请大家多多关注我的酷米号,谢谢大家!
网友解答:java web中编写html常见的方法:
1、直接编写静态的html文件,不具备动态功能。
2、直接拼接html字符串,在servlet中使用response的输出流输出。
3、使用jsp编写html。
4、使用模板引擎编写html,常见的如velocity,freemarker等。