最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用JSP生成靜態(tài)頁(yè)面

 更新時(shí)間:2007年01月05日 00:00:00   作者:  
主要原理請(qǐng)參考http://blog.hunan2s.com/article.asp?id=233

經(jīng)過(guò)一翻調(diào)試,成功了。。呵

附上源碼。。


JDK 1.5 +ECLIPSE +TOMCAT 5.0.28 + MYSQL 5.0 

數(shù)據(jù)庫(kù)TEST ,表名news 
字段: id   int 自動(dòng)增長(zhǎng) , 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() 返回可以不受阻塞地從此文件輸入流中讀取的字節(jié)數(shù)。

byte bytes[] = new byte[lenght];

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

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

// 根據(jù)時(shí)間得文件名
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();
    }



  %>

//數(shù)據(jù)庫(kù)連接文件

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>

相關(guān)文章

  • IBM HTTP Server 遠(yuǎn)程溢出漏洞

    IBM HTTP Server 遠(yuǎn)程溢出漏洞

    IBM HTTP Server 遠(yuǎn)程溢出漏洞...
    2006-10-10
  • struts json 類型異常返回到j(luò)s彈框問(wèn)題解決辦法

    struts json 類型異常返回到j(luò)s彈框問(wèn)題解決辦法

    這篇文章主要介紹了struts json 類型異常返回到j(luò)s彈框問(wèn)題解決辦法的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • 用JSP編寫(xiě)文件上傳

    用JSP編寫(xiě)文件上傳

    用JSP編寫(xiě)文件上傳...
    2006-10-10
  • 在jsp頁(yè)面中響應(yīng)速度提高的7種方法分享

    在jsp頁(yè)面中響應(yīng)速度提高的7種方法分享

    這篇文章介紹了在jsp頁(yè)面中響應(yīng)速度提高的7種方法,有需要的朋友可以參考一下
    2013-09-09
  • 最新評(píng)論

    句容市| 乐至县| 灵丘县| 军事| 虎林市| 金秀| 乐业县| 连城县| 深州市| 咸宁市| 乌兰县| 宁国市| 资中县| 平凉市| 丰镇市| 东阳市| 大悟县| 连州市| 仁怀市| 共和县| 容城县| 景谷| 伊金霍洛旗| 蓬莱市| 吴旗县| 泸西县| 陇川县| 盐边县| 武冈市| 九龙坡区| 博白县| 家居| 伊吾县| 宣汉县| 治多县| 五原县| 武宁县| 图们市| 深圳市| 开化县| 兴隆县|