- 1、jsp 中網站的首頁源代碼
- 2、如何用jsp代碼把當前頁設置為主頁
- 3、求一個jsp博客項目源代碼
這是最簡單的一個例子,數據庫要你自己建,用的是ACCESS
%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”” %
html
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″
titleJSP連接Access數據庫/title
style type=”text/css”
!–
.style1 {
font-size: 20px;
font-weight: bold;
}
—
/style
/headbody
div align=”center” class=”style1″JSP連接Access數據庫/div
br
hr
p%
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //載入驅動程序類別
Connection con = DriverManager.getConnection(“jdbc:odbc:jspdata”); //建立數據庫鏈接,jspdata為ODBC數據源名稱
//建立Statement對象
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(“select * from lyb”); //建立ResultSet(結果集)對象,並執行SQL語句
%
/p
p align=”center”NUMB1數據表中記錄如下/p
table width=”640″ border=”1″ align=”center” bordercolor=”#7188e0″
tr bgcolor=”d1d1ff”
th width=”49″編號/th
th width=”90″姓名/th
th width=”126″E-mail/th
th width=”221″網站/th
th width=”80″QQ/th
/tr
%
while(rs.next())
{
%
tr bgcolor=”#f8f8f8″
th%= rs.getString(1) %/th
th%= rs.getString(2) %/th
th%= rs.getString(3) %/th
th bgcolor=”#f6f6f8″%= rs.getString(4) %/th
th%= rs.getString(5) %/th
/tr
%
}
rs.close();
stmt.close();
con.close();
%
/table
p align=”center”br
如果您能看到表格中的數據,說明連接數據庫成功!/p
/body
/html
將下面代碼嵌入你的jsp body中想設為主頁的位置:
a href=# onClick=”this.style.behavior=’url(#default#homepage)’;this.setHomePage(『你的網址』);”設為首頁/a
我這有好多套基於jsp servlet的博客系統代碼,這個本質上就是一個內容管理系統,代碼的數據庫用的是mysql,希望能夠幫到你
原創文章,作者:AMHJ8,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/126851.html