求朋友给看看,问题出在哪
下面这段代码读取数据库字段中汉字乱码,求朋友给看看,问题出在哪,给个解。
<%
dim dsn,conn
dsn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.MapPath("db.mdb")&""
on error resume next
set conn=server.CreateObject("adodb.connection")
conn.Open dsn
if err then
err.clear
set conn=nothing
response.write("<html><head><title>警告!发生常规性错误!</title></head><body style=""margin:0px;background-color:#eeeeee""><br><br><b><font size=4>警告:因为当前系统发现系统设置错误,导致不能连接到数据库!<br>请您检查/conn.asp文件第二行的数据库联接字符串是否正确<br><br>如果您不能解决此问题,请联系管理员来修正该问题</font><br></body></html>")
end if
sub closeconn()'系统事件:关闭数据库连接,节省服务器资源
conn.close
set conn=nothing
end sub
sub showmsg(msg)
response.write("<script language=javascript>alert('"&msg&"');</script>")
end sub
sub gotourl(url)
response.write("<script language=javascript>location.href='"&url&"';</script>")
end sub
sub back(num)
response.write("<script language=javascript>history.back("&num&");</script>")
end sub
sub closewindows()
response.write("<script language=javascript>window.close();</script>")
end sub
function filterstr(strChar)
if strChar="" then
filterstr=""
else
filterstr=replace(replace(replace(replace(replace(replace(replace(strChar,"'",""),"*",""),"?",""),"(",""),")",""),"<",""),".","")
end if
end function
%><%
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open "Select * From tree order by orderID asc", Conn,1,1
%>
<html>
<head>
<title>系统栏目树的管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" src="images/TreeView.js"></script>
<link href="images/Global.css" type="text/css" rel="stylesheet">
<style>
A.MzTreeview
{
font-size: 9pt;
padding-left: 3px;
}
</style>
</head>
<body class=frame>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.tree = new MzTreeView("tree");
tree.icons["property"] = "property.gif";
tree.icons["css"] = "collection.gif";
tree.icons["book"] = "book.gif";
tree.iconsExpand["book"] = "bookopen.gif"; //展开时对应的图片
tree.setIconPath("images/"); //可用相对路径,留空为当前路径
<%
Dim node
Dim reg : set reg = new RegExp : reg.global=True : reg.pattern=";"
Dim id, parentId, text, hint, icon, data, url, target, method
do while not rs.eof
'若是树的条目比较多的时候(比如大于1000)而又相对稳定的时候将这些数据生成静态网页来访问
node = VBCrLf &" tree.nodes["""& rs("parentId") &"_"& rs("id") &"""] = """
node = node &"text:"& reg.replace(rs("text"), chr(15)) &";"
if rs("hint")<>"" then node = node &"hint:"& reg.replace(rs("hint"), chr(15)) &";"
if rs("icon")<>"" then node = node &"icon:"& rs("icon") &";"
if rs("data")<>"" then node = node &"data:"& reg.replace(rs("data"), chr(15)) &";"
node = node &"url:tree_edit.asp?id="&rs("id")&";"
if rs("target")<>"" then node = node &"target:"& rs("target") &";"
if rs("method")<>"" then node = node &"method:"& reg.replace(rs("method"), chr(15)) &";"
response.write node &"""" '生成节点信息
rs.movenext
loop
%>
tree.setTarget("tree_edit");
document.write(tree.toString()); //亦可用 obj.innerHTML = tree.toString();
//-->
</SCRIPT>
</body>
</html>
<%
rs.close : set rs = nothing : Conn.close : set Conn = nothing
%>
[解决办法]
出现乱码就是你编码的问题喽!!<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
[解决办法]
如果网页头部设置了UTF-8编码后,还要再把页面文件设置为UTF-8,方法是:记事本打开这个页面,然后选择另存为,编码默认是ANSI,改为,UFT-8.中文就会生效了。
如果网页头部编码是GB2312,就不需要有此步骤。