1 Star 0 Fork 0

不经意间的微笑 / 11

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
JspToHtml.java 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
不经意间的微笑 提交于 2017-08-09 11:24 . Upload JspToHtml.java
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);
}
}
Java
1
https://gitee.com/digouyou/11.git
git@gitee.com:digouyou/11.git
digouyou
11
11
master

搜索帮助