展开全部
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();
}
}
}
}
}
参数解释:
page:jsp页面的网络地址,比如http://localhost:8080/xxx/index.jsp
filePath:生成的html文件的保存路径
chartset:编码,不填默认utf-8。
思想:
把jsp文件开流读入,再用输出流写入到目标文件。
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();
}
}
}
}
}
参数解释:
page:jsp页面的网络地址,比如http://localhost:8080/xxx/index.jsp
filePath:生成的html文件的保存路径
chartset:编码,不填默认utf-8。
思想:
把jsp文件开流读入,再用输出流写入到目标文件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询