Andy Luo:
          1、在生成頁(yè)面后更新數(shù)據(jù)庫(kù)中鏈接地址,或做一個(gè)標(biāo)記,使得主頁(yè)上各篇文章的鏈接地址指向靜態(tài)頁(yè)面。
          2、在第一次訪問(wèn)文章時(shí)創(chuàng)建靜態(tài)頁(yè)面,或在服務(wù)器定時(shí)查詢新增紀(jì)錄並生成靜態(tài)頁(yè)面
          3、訪問(wèn)主業(yè)時(shí)也可生成靜態(tài)網(wǎng)葉,通過(guò)查詢數(shù)據(jù)庫(kù)中一個(gè)記錄,獲取最新文章的錄入時(shí)間,比較並更新主業(yè)的靜態(tài)網(wǎng)葉

          轉(zhuǎn)自:http://blueline.hit.edu.cn/ccs/blogs/loveme/archive/2006/03/03/1030.aspx

          為了減輕服務(wù)器壓力,將原來(lái)的文章管理系統(tǒng)由JSP文件的從數(shù)據(jù)庫(kù)中取數(shù)據(jù)顯示改為由jsp生成靜態(tài)html文件后直接訪問(wèn)html文件。下面是一個(gè)簡(jiǎn)單的示例

          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.print(filePath+"<br>");
           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);//建立文件輸出流
           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>



          版權(quán)所有 羅明
          posted on 2006-03-05 22:05 羅明 閱讀(2643) 評(píng)論(3)  編輯  收藏 所屬分類: Server
          Comments
           
          主站蜘蛛池模板: 榆社县| 垣曲县| 大厂| 德州市| 鹤庆县| 兴业县| 镇江市| 赤峰市| 洛宁县| 收藏| 贵阳市| 金门县| 攀枝花市| 罗山县| 麦盖提县| 普陀区| 弥勒县| 正定县| 东港市| 启东市| 慈利县| 汝阳县| 龙海市| 河曲县| 张家口市| 辽阳市| 金昌市| 安仁县| 仙居县| 南开区| 芒康县| 屯昌县| 五华县| 勃利县| 琼中| 全椒县| 三亚市| 洪湖市| 都兰县| 宁安市| 廉江市|