jsp动态生成静态页面(2)
FileWriter fileWriter=new FileWriter(htmlFile,true);
BufferedWriter bufferedWriter=new BufferedWriter(fileWriter);
bufferedWriter.write(fileContent);
bufferedWriter.close();
fileWriter.close();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//generate html filename according to request url
public static String generateFileName(String url)
{
String preFileName=url.substring(url.lastIndexOf("/"));
//需要把请求参数中的"?"转换一下 否则文件名不能出现问号
String fileName=preFileName.replace("?", URLEncoder.encode("?"));
return fileName.replace(".", "_")+".html";
}
}
/**
* @author jeedroid
* @time 2011-11-24 00:47:52
*/
package com.jeedroid.makehtml;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class MakeHtml
{
public static void makeHtml(String url)
{
try {
//读取要访问的文件的内容
相关新闻>>
- 发表评论
-
- 最新评论 更多>>