jsp 生成静态页面

字体大小: 中小 标准 ->行高大小: 标准
package com.mobiAdList.tool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;


/** 
* Filename: JspToHtml.java 
* Ttitle: 
* Description: 
* Copyright: Copyright (c) 2001-2004 BlueStar,Inc.All Rights Reserved. 
* Company: bluestar 
* Author: <a href= "mailto:lanxingsc@163.com "> wuyang </a> 
* Telephone: 86-28-85239210 
* Date: 2004-6-19 
* Time: 16:41:09 
* Version: 1.0.1.0000 
*/ 
public class JspToHtml {


/** 
* 根据url生成静态页面 
* 
* @param u 动态文件路经 如:http://www.sina.com/kkk.jsp 
* @param path 文件存放路经如:d:\\aaa\bbb.html 
* @return 
*/ 
public static boolean JspToHtmlByURL(String u , String path) { 
//从utl中读取html存为str 
String str = ""; 
try { 
URL url = new URL(u); 
URLConnection uc = url.openConnection(); 
InputStream is = uc.getInputStream(); 
BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
while(br.ready()) { 
str += br.readLine() + "\n "; 
} 

is.close(); 
//写入文件 
File f = new File(path); 

OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(f),"UTF-8");
outputStreamWriter.write(str); 
outputStreamWriter.close(); 
return true; 
}catch(IOException e){ 
e.printStackTrace();
return false; 
} 
}

/** 
* 测试 
* 
* @param arg 
*/ 
public static void main(String[] arg) { 
String url = "http://www.baidu.com"; 
String savepath = "d:\\aaa.xml"; 
JspToHtmlByURL(url , savepath); 
}

}

此文章由 www.phpgz.com 收集整理 ,地址为: http://www.phpgz.com/htmls/69086.html

大屏阅读,大屏评论.