jsp页面获取数据后怎样生成HTML静态页面
1个回答
2016-08-12 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
public class HTMLMaker {
final static Object lock = new Object();
public static void makeHtml(String page, String filePath){
makeHtml(page,filePath,"UTF-8");
}
public static void makeHtml(String page, String filePath,String chartset) {
synchronized (lock) {
HttpURLConnection huc = null;
BufferedReader br = null;
BufferedWriter bw = null;
try {
huc = (HttpURLConnection)new URL(page).openConnection();
System.setProperty("sun.net.client.defaultConnectTimeout", "衡码和30000"咐盯);
System.setProperty("sun.net.client.defaultReadTimeout"模销, "30000");
huc.connect();
InputStream stream = huc.getInputStream();
bw = new BufferedWriter(new OutputStreamWriter (new FileOutputStream(filePath),chartset));
br = new BufferedReader(new InputStreamReader(stream, chartset));
String line;
while((line = br.readLine())!= null){
if(line.trim().length() > 0){
bw.write(line);
bw.newLine();
}
}
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
bw.close();
huc.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
final static Object lock = new Object();
public static void makeHtml(String page, String filePath){
makeHtml(page,filePath,"UTF-8");
}
public static void makeHtml(String page, String filePath,String chartset) {
synchronized (lock) {
HttpURLConnection huc = null;
BufferedReader br = null;
BufferedWriter bw = null;
try {
huc = (HttpURLConnection)new URL(page).openConnection();
System.setProperty("sun.net.client.defaultConnectTimeout", "衡码和30000"咐盯);
System.setProperty("sun.net.client.defaultReadTimeout"模销, "30000");
huc.connect();
InputStream stream = huc.getInputStream();
bw = new BufferedWriter(new OutputStreamWriter (new FileOutputStream(filePath),chartset));
br = new BufferedReader(new InputStreamReader(stream, chartset));
String line;
while((line = br.readLine())!= null){
if(line.trim().length() > 0){
bw.write(line);
bw.newLine();
}
}
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
bw.close();
huc.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询