讀取資料庫中的html
A. html如何把資料庫中讀取的html標簽輸出
第一步:將取出的標簽轉換成字元槐早磨串,比如:
var html = "鉛斗<div>這就是標簽字元串</div>"
第二步:
在睜哪html中的節點插入:
document.body.innerHTML = html
就完成了
B. JSP中從mysql資料庫中讀取含有html標簽的數據問題
要想拿森叢從資料庫讀取帶有html標春基簽的數據,首先存放資料庫就要是含有HTML的數據
用FCKeditor保存數據,然後讀取就是含有html標簽的消櫻數據了
。。。你可以試試
C. html從資料庫中讀取數據
html只能通過ajax介面跟後台資料庫介面通信,然態穗後取出來的數據在頁面上顯示。
以下是一個例子:
html文件suggest.html:帆虛卜
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="javaScript" type="text/javascript" src="ajax_search.js"></script>
<style type="譽胡text/css" media="screen">
body {
font: 11px arial;
}
.suggest_link {
background-color: #FFFFFF;
padding: 2px 6px 2px 6px;
cursor:hand;
}
.suggest_link_over {
background-color: #E8F2FE;
padding: 2px 6px 2px 6px;
}
#search_suggest {
position:relative;
background-color: #FFFFFF;
text-align: left;
border: 1px solid #000000;
left: -12px;
top: 1px;
height: 74px;
width: 170px;
display:none;
}
</style>
</head>
<body background="bg.gif">
<center>
<h3>實現搜索提示</h3>
<div style="width: 500px;">
<input type="text" id="txtSearch" name="txtSearch" onKeyUp="searchSuggest();" autocomplete="off" />
<input type="submit" id="cmdSearch" name="cmdSearch" value="搜索"/><br />
<div id="search_suggest"></div>
</div>
</center>
</body>
</html>
ajax_search.js:
var searchReq = createAjaxObj();
function createAjaxObj()
{
var httprequest=false;
if (window.XMLHttpRequest) //為非IE瀏覽器生成XmlHttpRequest對象
{
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject) //為IE瀏覽器生成XmlHttpRequest對象
{
try
{
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}
function searchSuggest()
{
if (searchReq.readyState == 4 || searchReq.readyState == 0)
{
D. html如何把資料庫中讀取的html標簽輸出
一般富文本編輯器保存的文章排版都是添加了跟多html或者css代碼咐啟保存到資料庫的,為就是後台預言可以直接從資料庫中取出來放到html頁面顯示那些樣式和排版,此時後台讀取到衡鍵如帶有html標記的數據應該是交給JavaScript,使用JavaScript的一些方法將數據展現在頁面上輸出。
工具原料:jQuery、編輯器、瀏覽器
1、首先假設後台讀取到的數據通過ajax傳給了前端的JavaScript,JavaScript獲取的數據後使用html方法將其輸出在頁面的亮渣某個標簽中,在這里我們使用模擬數據來代替數據的傳輸過程,代碼如下:
<body>
<scriptsrc="libs/jquery/2.1.4/jquery.js"></script>
<divid="div1">
</div>
<script>
vardata="<fontcolor='red'>測試數據</font>";//帶有html標簽的測試數據
$('#div1').html(data);//通過html()方法將數據輸出到div中
</script>
</body>
2、運行的效果如下圖:
E. 資料庫中的html 怎麼顯示出來
1、首先通過php或者jsp等後台語言獲取資料庫中的內容,保存到變數cont中。2、調用editor.setContent(cont)就完成數據賦值到編輯器中了,這里的editor是編輯器實例。PS:如果在點擊諸如「編輯」按鈕之後再實例化編輯器,然後設置內容時,通常需要等待編輯器實例化完成之後再賦值,也就是代碼需要改成這樣子:editor.ready(function(){ editor.setContent(cont); })否則在某些情況下會報錯。當然,如果點擊編輯的時候編輯器已經顯示在桌面上了的時候,那就只需要直接調用即可。
F. php從資料庫里讀出的HTML代碼然後執行怎麼實現
<?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //選擇資料庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標題','新聞內容'),array('新聞標題2','新聞內容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夾不存在,則自動建立一個
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只讀打開模板
$str=fread($fp,filesize("tmp.htm"));//讀取模板中內容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內容寫進生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //刪除文件
?><?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //選擇資料庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標題','新聞內容'),array('新聞標題2','新聞內容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夾不存在,則自動建立一個
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只讀打開模板
$str=fread($fp,filesize("tmp.htm"));//讀取模板中內容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內容寫進生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //刪除文件
?><?php require_once("mysql_class.php");
require_once("sys_conf.inc");
header('Content-Type:text/html;Charset=GBK;');
$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
mysql_select_db($DBNAME); //選擇資料庫my_chat
$sql="SELECT * FROM `dx_leibie`";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){
//print_r($row); //$con=array(array('新聞標題','新聞內容'),array('新聞標題2','新聞內容2')); $title=$row[id_lang];
$content=$row[name];
if(!is_dir("up")) //如果此文件夾不存在,則自動建立一個
{
mkdir("up");
}$up="up/";
echo $path=$up.$row[id_lang].'.htm';
$fp=fopen("tmp.htm","r"); //只讀打開模板
$str=fread($fp,filesize("tmp.htm"));//讀取模板中內容
$str=str_replace("{title}",$title,$str);
echo $str=str_replace("{content}",$content,$str);//替換內容
fclose($fp); $handle=fopen($path,"w"); //寫入方式打開新聞路徑
fwrite($handle,$str); //把剛才替換的內容寫進生成的HTML文件
fclose($handle);
//echo "生成成功";
} // unlink($path); //刪除文件
?> 用以上先生成一個HTML文件,然後再用require_once("aaa.html");引進來就OK
G. 如何將從資料庫中讀出的帶有html標簽的字元串,讓標簽起效,顯示在
H. 資料庫存入html怎麼讀取
讀出二進鉛改罩制,轉化成槐鬧流殲碧,然後write到頁面上
byte[] blob = userinfo.getPhoto();
if(blob!=null){
response.reset(); response.setContentType("image/"+dat); OutputStream toClient = response.getOutputStream(); try { toClient.write(blob); } catch (Exception e) { e.printStackTrace(); }finally{ toClient.flush(); toClient.close(); } response.flushBuffer(); }
寫資料庫
byte[] bFile = new byte[(int) files[0].length()];FileInputStream fileInputStream = new FileInputStream(files[0]);fileInputStream.read(bFile);fileInputStream.close();userinfo.setPhotoname(photoName[0]);userinfo.setPhoto(bFile);
user.save(userinfo);
我這個是java的,不知道和你的一不一樣
I. 如何讀取sql server資料庫中的html代碼
HTML是無法讀取資料庫的,HTML是頁面前端腳本語言,要想從HTML網頁中獲取SQL資料庫里的數據,需要藉助JSP或ASP或PHP或RUBY等語言來實現。 簡單的關系可以這樣理解: 資料庫<--->JSP或ASP或PHP或RUBY等語言<--->HTML
如:在JSP頁面中顯示完整代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<%@ page
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
<%@page import="java.sql.*"%>
<center>
<H1> <font color="blue" size="12">管理中心</font></H1>
<HR />
<table width="80%" border="1">
<tr>
<th>ID</th>
<th>書名</th>
<th>作者</th>
<th>價格</th>
<th>刪除</th>
</tr>
<%
// 資料庫的名字
String dbName = "zap";
// 登錄資料庫的用戶名
String username = "sa";
// 登錄資料庫的密碼
String password = "123";
// 資料庫的IP地址,本機可以用 localhost 或者 127.0.0.1
String host = "127.0.0.1";
// 資料庫的埠,一般不會修改,默認為1433
int port = 1433;
String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + ";databaseName=" + dbName + ";user=" + username
+ ";password=" + password;
//
//聲明需要使用的資源
// 資料庫連接,記得用完了一定要關閉
Connection con = null;
// Statement 記得用完了一定要關閉
Statement stmt = null;
// 結果集,記得用完了一定要關閉
ResultSet rs = null;
try {
// 注冊驅動
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 獲得一個資料庫連接
con = DriverManager.getConnection(connectionUrl);
String SQL = "SELECT * from note";
// 創建查詢
stmt = con.createStatement();
// 執行查詢,拿到結果集
rs = stmt.executeQuery(SQL);
while (rs.next()) {
%>
<tr>
<td>
<%=rs.getInt(1)%>
</td>
<td>
<a href="prepareupdate?ID=<%=rs.getInt("ID")%>" target="_blank"><%=rs.getString(2)%></a>
</td>
<td>
<%=rs.getString(3)%>
</td>
<td>
<%=rs.getString(4)%>
</td>
<td>
<a href="delete?ID=<%=rs.getInt("ID")%>" target="_blank">刪除</a>
</td>
</tr>
<%
}
} catch (Exception e) {
// 捕獲並顯示異常
e.printStackTrace();
} finally {
// 關閉我們使用過的資源
if (rs != null)
try {
rs.close();
} catch (Exception e) {}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {}
if (con != null)
try {
con.close();
} catch (Exception e) {}
}
%>
</table>
<a href="insert.jsp">添加新紀錄</a>
</center>