String title = "jsp生成静态html文件";
String content = "小样,还搞不定你?";
String editer = "hpsoft";
String filePath = "";
String templateContent = "";
FileInputStream fileinputstream = new FileInputStream( request.getRealPath("/") +"tmp.html" );//读取模块文件
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
templateContent = templateContent.replaceAll("###title###", title);
templateContent = templateContent.replaceAll("###content###",
content);
templateContent = templateContent.replaceAll("###author###", editer);//替换掉模块中相应的地方
// 根据时间得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis())
+ ".html";
filePath = request.getRealPath("/") +"html/" +calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH)+"/";//生成的html文件保存路径
File file = new File(filePath);
if(!file.exists())
{
file.mkdirs();
}
FileOutputStream fileoutputstream = new FileOutputStream(filePath + fileame);//建立文件输出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
request.getSession().getServletContext().getRealPath("/")