国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

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

2024-09-05 00:21:36
字體:
來源:轉載
供稿:網友

主要原理請參考?id=233

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

附上源碼。。


JDK 1.5 +ECLIPSE +TOMCAT 5.0.28 + MYSQL 5.0

數(shù)據(jù)庫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() 返回可以不受阻塞地從此文件輸入流中讀取的字節(jié)數(shù)。

byte bytes[] = new byte[lenght];

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

fileinputstream.close();
//templateContent = new String(bytes);
String title;
String content;
String author;
while(Rs.next())
{
templateContent = new String(bytes);//如果不用這句,則替換一次之后,templateContent中就沒有#**#標志了。所以要重新生成
{
conn.close();
}
if(stmt!=null)
{
stmt.close();
}



%>

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

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 cellpadding="0" cellspacing="1" bgcolor="#FFCC99">
<tr>
<td bgcolor="#FFCC99"><div>#title#</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">#content#</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">#author#</td>
</tr>
</table>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 神木县| 南投市| 闸北区| 柳江县| 武城县| 甘肃省| 武平县| 栾城县| 乾安县| 龙陵县| 米易县| 保德县| 德庆县| 合阳县| 千阳县| 灵丘县| 新干县| 洞头县| 多伦县| 陇西县| 大方县| 邯郸县| 思茅市| 三河市| 东乡族自治县| 中江县| 盘山县| 若羌县| 滨州市| 吴忠市| 仙居县| 广水市| 增城市| 长白| 曲松县| 黔东| 上林县| 清原| 武川县| 商都县| 泗洪县|