国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

JSP頁(yè)面自動(dòng)生成html頁(yè)面或任何格式頁(yè)面

2024-09-05 00:16:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

先建立一個(gè)模本頁(yè)面:template.htm



###title###














###title###
作者:###author###
###content###



=========================================
再寫(xiě)一個(gè)JSP頁(yè)面: buildhtml.jsp

<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
String title="jsp生成靜態(tài)html文件";
String content="小樣,還搞不定你?";
String editer="CuoXIncom";
String filePath = "";
filePath = request.getRealPath("/") "template.htm";
out.print(filePath);
String templateContent="";
FileInputStream fileinputstream = new FileInputStream(filePath);//讀取模塊文件
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
out.print(templateContent);
templateContent=templateContent.replaceAll("###title###",title);
templateContent=templateContent.replaceAll("###content###",content);
templateContent=templateContent.replaceAll("###author###",editer);//替換掉模塊中相應(yīng)的地方
out.print(templateContent);
// 根據(jù)時(shí)間得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) ".html";
fileame = request.getRealPath("/") fileame;//生成的html文件保存路徑
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流
out.print("文件輸出路徑:
");
out.print(fileame);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(Exception e){
out.print(e.toString());
}
%>

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 旬阳县| 湘潭市| 香格里拉县| 西藏| 滨州市| SHOW| 新丰县| 涡阳县| 海门市| 青河县| 公主岭市| 杭锦旗| 武平县| 柯坪县| 高雄县| 温泉县| 定南县| 睢宁县| 行唐县| 萨嘎县| 济阳县| 五台县| 凤山县| 舟曲县| 蓝山县| 柳林县| 青岛市| 大冶市| 合川市| 耿马| 玛曲县| 商洛市| 阿克苏市| 应用必备| 香河县| 宜宾市| 三江| 济宁市| 娄烦县| 古丈县| 三门峡市|