經過一翻調試,成功了。。呵

附上源碼。。

JDK 1.5 +ECLIPSE +TOMCAT 5.0.28 + MYSQL 5.0

數據庫TEST ,表名news 字段: id int 自動增長 , Title v " /> 青青草原直播,x8国产精品视频,含羞草影院免费区

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

用JSP生成靜態頁面

主要原理請參考http://blog.hunan2s.com/article.ASP?id=233

經過一翻調試,成功了。。呵

附上源碼。。


JDK 1.5 +ECLIPSE +TOMCAT 5.0.28 + MYSQL 5.0 

數據庫TEST ,表名news 
字段: id   int 自動增長 , Title  varchar(20) , Content  varchar(200)  , Author  varchar(10) 

makeFile.jsp

 <%
  Connection conn = DBconn.getConnection();
  Statement stmt = conn.createStatement();
  ResultSet Rs = stmt.executeQuery("select * from news");
  System.out.println("success");

 %>

  <%

  String filePath = request.getRealPath("/")+"template.htm";

  System.out.println(filePath);

  String templateContent;
  FileInputStream fileinputstream = new FileInputStream(filePath);
  int lenght = fileinputstream.available(); //available() 返回可以不受阻塞地從此文件輸入流中讀取的字節數。

byte bytes[] = new byte[lenght];

fileinputstream.read(bytes); //read(byte[] b) 從此輸入流中將最多 b.length 個字節的數據讀入一個字節數組中。

fileinputstream.close();
//templateContent = new String(bytes);
String title;
String content;
String author;
while(Rs.next())
{
templateContent = new String(bytes);//如果不用這句,則替換一次之后,templateContent中就沒有#**#標志了。所以要重新生成
 title = Rs.getString("Title");
 content = Rs.getString("Content");
 author = Rs.getString("Author");
out.println(title+"********"+content+"****"+author);
out.print("以下是模板內容:<br>"+templateContent+"<br> 以下是置換以后的html內容<br><hr>");
templateContent=templateContent.replaceAll("#title#",title);
templateContent=templateContent.replaceAll("#author#",author);//替換掉模塊中相應的地方
templateContent=templateContent.replaceAll("#content#",content);

// 根據時間得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+"Html/"+fileame;//生成的html文件保存路徑


out.print(templateContent);
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();

}

if(conn!=null)
    {
        conn.close();
    }
    if(stmt!=null)
    {
        stmt.close();
    }



  %>

//數據庫連接文件

import Java.sql.*;
public class DBconn {

    public DBconn() {

        // TODO Auto-generated constructor stub
    }

    public static Connection getConnection() 
    {
        Connection conn = null;

        try { 
            Class.forName("org.gjt.mm.mysql.Driver"); 
            conn = DriverManager.getConnection("jdbc:mysql://" + "localhost" + "/" + "test" +
        "?useUnicode=true&characterEncoding=GB2312","root","111111"); 

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return conn;
        }
    /*public static void main(String[] args) throws Exception
    {
        Connection con=getConnection();
        System.out.println(con.isClosed());

    }
*/
}



// 模板文件

template.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>#title#</title>
</head>

<body>
<table width="380" height="107" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFCC99">
  <tr>
    <td height="16" bgcolor="#FFCC99"><div align="center">#title#</div></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">#content#</td>
  </tr>
  <tr>
    <td height="13" align="right" bgcolor="#FFFFFF">#author#</td>
  </tr>
</table>
</body>
</html>

jsp技術用JSP生成靜態頁面,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 动漫护士被乳羞羞漫 | 国产免费阿v精品视频网址 国产免费69成人精品视频 | 99视频这里只有精品国产 | 日韩精品无码视频一区二区蜜桃 | 亚洲国产果果在线播放在线 | 国产精品AV视频一二三区 | xx69美国 | 久久久无码AV精品亚洲A片软件 | 国产美女又黄又爽又色视频网站 | 一二三四在线观看高清电视剧 | 亚洲综合日韩中文字幕v在线 | 欧美牲交A欧美牲交 | 寻找最美乡村教师颁奖晚会 | 一个人免费视频在线观看高清版 | 亚洲福利精品电影在线观看 | 欧美老妇与zozoz0交 | 国产亚洲欧洲日韩在线观看 | 久久99热狠狠色AV蜜臀 | 灰原哀被啪漫画禁漫 | adc网址在线观看 | 日韩中文网| 亚洲视频中文字幕在线 | 一本之道高清在线3线观看 一本之道高清视频在线观看 | 欧美巨大巨粗黑人性AAAAAA | 激情内射亚州一区二区三区爱妻 | 最好看中文字幕国语 | 国产精品欧美亚洲 | TIMI1TV天美传媒在线观看 | 国产成人a在一区线观看高清 | 92国产精品午夜免费福利视频 | 亚洲精品乱码久久久久久v 亚洲精品乱码电影在线观看 | 无人区日本电影在线观看 | 99日精品欧美国产 | 野花日本韩国视频免费高清观看 | 亚洲涩福利高清在线 | 精品一区二区三区AV天堂 | 绝对诱惑在线试听 | 亚洲综合AV在线在线播放 | 琉璃美人煞在线观看 | 入禽太深在线观看免费高清 | 动漫美女喷水 |