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

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

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

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

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

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

    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
     
    主站蜘蛛池模板: 国产av无码专区亚洲av桃花庵| 国产亚洲精品看片在线观看| 91嫩草免费国产永久入口| 久久精品国产免费| 18禁美女黄网站色大片免费观看| 成年美女黄网站色大免费视频| 在线播放高清国语自产拍免费| 免费一级毛片在播放视频| 久久精品国产精品亚洲蜜月| 亚洲狠狠成人综合网| 特级毛片免费播放| 久久精品乱子伦免费| 国产精品嫩草影院免费| 婷婷亚洲久悠悠色悠在线播放| 亚洲精品无码mⅴ在线观看| 亚洲avav天堂av在线网爱情| 国产精品亚洲色图| 亚洲免费人成视频观看| 亚洲欧洲日产韩国在线| av片在线观看永久免费| 福利免费观看午夜体检区| 国产亚洲精品AA片在线观看不加载| 成年免费大片黄在线观看com| 色窝窝免费一区二区三区| 最新亚洲精品国偷自产在线| 日本黄页网站免费| 亚洲精品美女久久久久| 久久久久久国产a免费观看不卡| 无码国产精品一区二区免费| 亚洲va久久久噜噜噜久久狠狠| 久久国产色AV免费观看| 亚洲一区爱区精品无码| 综合偷自拍亚洲乱中文字幕| 一个人免费高清在线观看| 亚洲欧美国产欧美色欲| 免费一级国产生活片| 你好老叔电影观看免费| 四虎永久免费观看| 亚洲国产精品网站在线播放| 亚洲精品亚洲人成在线观看下载| 亚洲最大av资源站无码av网址|