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

首頁 > 編程 > JSP > 正文

JSP生成靜態頁實踐及其設計思想[2]

2019-11-18 16:39:29
字體:
來源:轉載
供稿:網友

為了減輕服務器壓力,將原來的文章管理系統由jsp文件的從數據庫中取數據顯示改為由jsp生成靜態html文件后直接訪問html文件。下面是一個簡單的示例

1.builDHTML.jsp

<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
 String title="This is Title";
 String content="This is Content Area";
 String editer="LaoMao";
 String filePath = "";
 filePath = request.getRealPath("/")+"test/template.htm";
 //out. 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);//替換掉模塊中相應的地方
 //out.print(templateContent);
 // 根據時間得文件名
 Calendar calendar = Calendar.getInstance();
 String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
 fileame = request.getRealPath("/")+fileame;//生成的html文件保存路徑
 FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流
 byte tag_bytes[] = templateContent.getBytes();
 fileoutputstream.write(tag_bytes);
 fileoutputstream.close();
}
catch(Exception e){
 out.print(e.toString());
}

%>

2. template.htm

<html>
<head>
<title>###title###</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../
CSS.css" rel=stylesheet type=text/css>
</head>

<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="2">
  <tr>
    <td align="center">###title###</td>
  </tr>
  <tr>
    <td align="center">author:###author###&nbsp;&nbsp;</td>
  </tr>
  <tr>
    <td>###content###
 </td>
 
  </tr>

</table>
</body>
</html>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 合川市| 绥中县| 垦利县| 时尚| 台南县| 台北市| 三台县| 隆昌县| 甘肃省| 宝丰县| 商南县| 维西| 沧源| 海南省| 原阳县| 梅河口市| 新兴县| 平舆县| 印江| 宁德市| 循化| 和平县| 宁河县| 清丰县| 汶川县| 平凉市| 玉林市| 高州市| 景泰县| 青铜峡市| 祥云县| 新乐市| 万安县| 和龙市| 前郭尔| 丰顺县| 华容县| 普兰县| 富顺县| 时尚| 威宁|