Java中怎么寫HTML?
網(wǎng)友解答: 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(); } } }}
上面是 源碼,這個(gè)比較簡(jiǎn)單,下面是圖片顯示:
請(qǐng)大家多多關(guān)注我的酷米號(hào),謝謝大家!
網(wǎng)友解答:java web中編寫html常見的方法:
1、直接編寫靜態(tài)的html文件,不具備動(dòng)態(tài)功能。
2、直接拼接html字符串,在servlet中使用response的輸出流輸出。
3、使用jsp編寫html。
4、使用模板引擎編寫html,常見的如velocity,freemarker等。