Java學(xué)習(xí)

          java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經(jīng)搬家了,新的地址是 http://www.javaly.cn 如果有對(duì)文章有任何疑問或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂園)指出,我會(huì)盡力幫助解決。一起進(jìn)步

           

          用JSP生成HTM網(wǎng)頁,減輕數(shù)據(jù)庫操作!

          模本頁面: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###  </td>
          </tr>
          <tr>
          <td>###content###
          </td>

          </tr>

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

          =========================================
          JSP文件: buildhtml.jsp

          <%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
          <%
          try{
          String title="jsp生成靜態(tài)html文件";
          String content="小樣,還搞不定你?";
          String editer="hpsoft";
          String filePath = "";
          filePath = request.getRealPath("/")+"template.htm";
          out.print(filePath);
          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);//建立文件輸出流
          out.print("文件輸出路徑:<br>");
          out.print(fileame);
          byte tag_bytes[] = templateContent.getBytes();
          fileoutputstream.write(tag_bytes);
          fileoutputstream.close();
          }
          catch(Exception e){
          out.print(e.toString());
          }

          %>

          posted on 2009-04-29 16:11 找個(gè)美女做老婆 閱讀(204) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          公告

          本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
           http://www.javaly.cn

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 平潭县| 缙云县| 且末县| 行唐县| 离岛区| 宝应县| 沾益县| 紫金县| 商都县| 贺州市| 邹平县| 阿荣旗| 泰安市| 临清市| 达尔| 正定县| 梅河口市| 鹤壁市| 虹口区| 兰西县| 临邑县| 容城县| 遂昌县| 文水县| 晋城| 江华| 黄平县| 千阳县| 浦县| 东阳市| 苗栗市| 正阳县| 清水县| 馆陶县| 古田县| 通河县| 海门市| 蓬莱市| 县级市| 巩义市| 溆浦县|