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

首頁 > 編程 > JSP > 正文

動態網頁變靜態:JSP生成靜態HTML技術

2024-09-05 00:19:45
字體:
來源:轉載
供稿:網友

下面的一段代碼是,使用jsp生成靜態html

<%@ page contenttype="text/html;charset=gbk"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*" %>
<%

//在這里如果寫成“web-inf/templates/template.htm”程序會報錯
 string filepath = request.getrealpath("/")+"web-inf/templates/template.htm";    
 out.print(filepath);
 string templatecontent="";

 fileinputstream fileinputstream = new fileinputstream(filepath);//讀取模塊文件
 //int lenght = fileinputstream.available();
 byte bytes[] = new byte[1024];
 fileinputstream.read(bytes);
 fileinputstream.close();

 templatecontent = new string(bytes);
 out.print("以下是模板內容:<br>"+templatecontent+"<br> 以下是置換以后的html內容<br><hr>");
 templatecontent=templatecontent.replaceall("#title#","文章標題");
 templatecontent=templatecontent.replaceall("#author#","作者是誰");//替換掉模塊中相應的地方
 templatecontent=templatecontent.replaceall("#content#","文章內容");

 // 根據時間得文件名
 calendar calendar = calendar.getinstance();
 string fileame = string.valueof(calendar.gettimeinmillis()) +".html";
 fileame = request.getrealpath("/")+fileame;//生成的html文件保存路徑

 out.print(templatecontent);
 fileoutputstream fileoutputstream = new fileoutputstream(fileame);//建立文件輸出流
 byte tag_bytes[] = templatecontent.getbytes();
 fileoutputstream.write(tag_bytes);
 fileoutputstream.close();
%>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 文化| 察哈| 富顺县| 成安县| 民乐县| 恩平市| 峨山| 汤原县| 喀喇| 宝应县| 长岛县| 静安区| 阳原县| 东乡县| 穆棱市| 兴城市| 太仆寺旗| 宜兰市| 碌曲县| 北碚区| 漳浦县| 阿拉尔市| 广水市| 寻甸| 嘉峪关市| 巨野县| 广南县| 延寿县| 新兴县| 新津县| 徐州市| 秦安县| 全州县| 洮南市| 甘孜| 黄浦区| 荥经县| 松桃| 马关县| 靖西县| 临沭县|