<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Andy Luo:
    1、在生成頁面后更新數據庫中鏈接地址,或做一個標記,使得主頁上各篇文章的鏈接地址指向靜態頁面。
    2、在第一次訪問文章時創建靜態頁面,或在服務器定時查詢新增紀錄並生成靜態頁面
    3、訪問主業時也可生成靜態網葉,通過查詢數據庫中一個記錄,獲取最新文章的錄入時間,比較並更新主業的靜態網葉

    轉自:http://blueline.hit.edu.cn/ccs/blogs/loveme/archive/2006/03/03/1030.aspx

    為了減輕服務器壓力,將原來的文章管理系統由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.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);//替換掉模塊中相應的地方
     //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>



    版權所有 羅明
    posted on 2006-03-05 22:05 羅明 閱讀(2643) 評論(3)  編輯  收藏 所屬分類: Server
    Comments
     
    主站蜘蛛池模板: 国产大片免费观看中文字幕| 久久午夜夜伦鲁鲁片免费无码| 亚洲国产区男人本色| 国产亚洲精品美女2020久久 | 18pao国产成视频永久免费| 亚洲高清中文字幕免费| 国产精品视频免费一区二区三区| 亚洲熟妇成人精品一区| 国产午夜精品理论片免费观看 | 日韩免费高清视频网站| 亚洲成在人天堂一区二区| 国产综合成人亚洲区| 国产成人精品男人免费| 新最免费影视大全在线播放| 最近免费中文字幕大全高清大全1| 俄罗斯极品美女毛片免费播放| 久久精品国产亚洲av四虎| 亚洲国产成人久久一区二区三区| 日本高清免费网站| 国产99久久久久久免费看| 国内免费高清在线观看| 亚洲美女人黄网成人女| 日日狠狠久久偷偷色综合免费| 亚洲一本大道无码av天堂| 亚洲国产精品免费观看| 国产成人精品无码免费看| 亚洲国产成人久久77| 国偷自产一区二区免费视频 | 亚洲va久久久噜噜噜久久男同| 免费不卡在线观看AV| 国产成人麻豆亚洲综合无码精品| 亚洲av永久无码精品三区在线4 | 亚洲AV无码一区二区三区电影| 免费观看美女用震蛋喷水的视频| 亚洲精品白浆高清久久久久久| 麻豆69堂免费视频| 在线观看视频免费国语| 亚洲国产av美女网站| 免费大黄网站在线看| 免费无码又爽又刺激高潮视频| 亚洲日韩AV一区二区三区四区|