package com.erry.util;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
/**
* 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另外为html页面
* 从属性文件bluestr中读取属怄1�7 TO_HTML_FILE
* 如:TO_HTML_FILE = index.do,aaa.html||error.jsp,errot.html
*
* @param request
*/
public static void JspToHtmlByProp(HttpServletRequest request) {
// String path = WebSite.getHostPath(request);
String path = request.getRealPath("");
// String realPath = request.getRealPath("/");
// String JspFile = "", HtmlFile = "";
String htmlFileString = ConfigUtil.getProp("TO_HTML_FILE");
String htmlFileString = ConfigUtil.getProp("TO_HTML_FILE");
// List l = StringUtil.splitList(htmlFileString, "||");
// if (l == null) l = new ArrayList();
// for (int k = 0; k < l.size(); k++) {
// String temp = (String) l.get(k);
// String str = "";
// JspFile = temp.substring(0, temp.indexOf(","));
// HtmlFile = temp.substring(temp.indexOf(",") + 1, temp.length());
// //从utl中读取html存为str
// try {
// URL url = new URL(path + JspFile);
// URLConnection uc = url.openConnection();
// InputStream is = uc.getInputStream();
// BufferedReader br = new BufferedReader(new InputStreamReader(is));
// while (br.ready()) {
// str += br.readLine() + "\n";
// }
// is.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// //写入文件
// try {
// File f = new File(realPath + HtmlFile);
// BufferedWriter o = new BufferedWriter(new FileWriter(f));
// o.write(str);
// o.close();
// } catch (IOException e) {
// }
// }
}
/**
* 根据url生成静�1�7�页靄1�7
*
* @param u 动�1�7�文件路组1�7 如: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));
while (br.ready()) {
str += br.readLine() + "\n";
}
is.close();
//写入文件
File f = new File(path);
BufferedWriter o = new BufferedWriter(new FileWriter(f));
o.write(str);
o.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* 测试
*
* @param arg
*/
public static void main(String[] arg) {
String url = "http://localhost/site/index.do";
// String savepath = "d:\\bb\\aaa.html";
String savepath= "C:\\jboss-4.0.4.GA\\server\\default\\deploy\\mag-gatewayApp.war\\site\\aa.html";
JspToHtmlByURL(url, savepath);
System.out.println("end");
}
}