關於JAVA生成HTML靜態頁,在前一家公司也寫過一些,可是很久沒有用,也有些遺忘了,好比關於路徑,就有點不清楚具體用那個類。
此次因爲公司的網站須要天天更新一個專題活動,破不得已,只好寫一個動態生成頁。如下作個記錄,以備往後參考:
JAVA頁面
/**
* 生成HTML頁面
*/
public
void hotread(){
String path = ServletActionContext.getServletContext().getRealPath(
"/");
String realPath = path+fileName+
".html";
File file=
new File(realPath);
try{
byte tag_bytes[] = content2.getBytes();
FileOutputStream out =
new FileOutputStream(file);
out.write(tag_bytes);
out.close();
}
catch(Exception e){ e.printStackTrace(); } }