代码拉取完成,页面将自动刷新
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
/**
*
* @author zyengogo
*
*/
public class JspToHtml {
private static long star = 0;
private static long end = 0;
private static long ttime = 0;
// 返回html代码
public static String getHtmlCode(String httpUrl, String bianma) {
Date before = new Date();
star = before.getTime();
String htmlCode = "";
try {
InputStream in;
URL url = new java.net.URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0");
connection.connect();
in = connection.getInputStream();
java.io.BufferedReader breader = new BufferedReader(new InputStreamReader(in, bianma));
String currentLine;
while ((currentLine = breader.readLine()) != null) {
htmlCode += currentLine;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
Date after = new Date();
end = after.getTime();
ttime = end - star;
// System.out.println("执行时间:"+ttime +"秒");
}
return htmlCode;
}
// 存储文件
public static synchronized void writeHtml(String filePath, String info) {
try {
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8");
out.write(info);
out.flush();
} catch (Exception ex) {
ex.getMessage();
}
}
//main调用
public static void main(String[] args) {
String url = "http://localhost:8080/ommp/initOperReportIndex.do";
writeHtml("c:/index.html",getHtmlCode(url,"utf-8"));
long tmp = Long.parseLong("0");
java.util.Date before = new java.util.Date();
long currtime = before.getTime();
System.out.println(currtime - tmp);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。