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);
}

}

posted @ 2012-02-23 16:47  镇水古月  阅读(179)  评论(0编辑  收藏  举报