| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1715 人关注过本帖
标题:ASP代码中乱码问题的解决
只看楼主 加入收藏
yourselsa
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-2-1
收藏
 问题点数:0 回复次数:6 
ASP代码中乱码问题的解决

这两段代码是两个不同聊天室的main框架主页的content部分的代码,为什么第一个没加content="text/html; charset=gb2312就不出现乱码呢?而另一个会出现乱吗呢
他们到底有什么不同?
第一段没出现乱码的代码
<html>
<head>
<meta http-equiv="refresh" content="10;url=content.asp">
<title>聊天内容</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<base target="ltop">
</head>

<body bgcolor="rgb(254,252,237)">


<%
'response.write application("AllCanSee")
'application("AllCanSee")=application("AllCanSee")& "you are welcome!<br>"
if application("Private" & session("NUM"))<>"/\" then
%>


<% =application("Private" & session("NUM")) %>


<% else %>
<%
'将其踢出聊天室

if session("NUM")<>"" then
application("VisitorNum")=application("VisitorNum")-1
application("Private" & session("NUM"))=""

dim i,j,num
i=1
j=1
num=0
dim Name(10)


'删除使用者名字和代号
do while j<>0
j=instr(i,application("VisitorName"),";",1)
if j<>0 then
num=num+1
str=mid(application("VisitorName"),i,j-i)
temppos=instr(1,str,",",1)+1
UserNum=mid(str,temppos)
if UserNum=cstr(session("NUM")) then
i=i-1
j=j+1
application("VisitorName")=mid(application("VisitorName"),1,i) & mid(application("VisitorName"),j)
exit do
end if
end if
i=j+1

loop
session("NUM")=""
session.abandon

end if
%>

<p><font color="#FF0000"><strong><font face="隶书"><big><big>不好意思,鉴于你的表现,你不能继续留在这!</big></big></font></strong>
<% end if %></font></p>
</body>
</html>




第二段出现乱码的文件


<html>
<head>
<!--??ò3??????10???ó?¢D?ò?′?-->
<meta http-equiv="refresh" content="10;url=content.asp?user=<%=UserID%>">
<title>á?ìì?úèY</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<base target="ltop">
</head>
<body bgcolor="rgb(254,252,237)">
<%
dim info
dim changed

set newconn=server.CreateObject("ADODB.Connection")
newconn.ConnectionString="DSN=ChatRoom"
newconn.Open
if Request.ServerVariables("REQUEST_METHOD")="GET" then
UserID=Request.QueryString("user")
myname=session("myname")'Request.QueryString("roomname")
end if
if Request.ServerVariables("REQUEST_METHOD")="POST" then
myname=Request.Form("userid")
UserID=myname
myroom=session("myroom")'Request.Form("roomname")
mynickname=Request.Form("mynickname")
newsql="update UserOnLine set TimeLastTalking='"&now&"'where UserID='"&UserID&"'"
newconn.Execute(newsql)
Application.Lock()

if left(Request.Form("T1"),1)="/"then
command=Request.Form("T1")
select case left(Request.Form("T1"),2)
case "/j"
newroom=trim(mid(Request.Form("T1"),4))
newsql="select RoomName,IfLocked,WhoCreate from RoomInfo where RoomName='"&newroom&"'"
set newrecord=newconn.Execute(newsql)
if newrecord.bof or newrecord.eof then
Application(UserID)="??óD?a??·???o?!<br><br>"&Application(UserID)
elseif newrecord("IfLocked")=true then
newsql="select UserID from UserOnLine where RoomName='"&newroom&"'and UserID='"&newrecord(2)&"'"
set myrecord=newconn.Execute(newsql)
if not myrecord.Bof then
Application(UserID)="?a??·???ò?é???,2??ü??è?£?<br><br>"&Application(UserID)
else
Create_Leaved=true
newsql="update RoomInfo set IfLocked=false where RoomName='"&newroom&"'"
newconn.execute(newsql)
end if
elseif Create_Leaved=false then
newsql1="select UserID from UserOnLine where RoomName='"&newroom&"'"

set newrecord1=server.CreateObject("ADODB.Recordset")
newrecord1.Open newsql1,"DSN=ChatRoom",1,3
do while not newrecord1.eof
tempname=cstr(newrecord1("UserID"))
if tempname<>UserID then
Application(tempname)="<br>"&mynickname&"′óò?′ó°úμ???à′á?£?£¨???¢D?)<font color=blue size=1>("&time()&")</font><br><br>"&Application(tempname)
end if
newrecord1.movenext
loop
newsql3="update RoomInfo set HowManyUsers=HowManyUsers+1 where RoomName='"&newroom&"'"
newconn.Execute(newsql3)
newsql4="update RoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='"&myroom&"'"
newconn.Execute(newsql4)
newsql2="update UserOnLine set RoomName='"&newroom&"'where UserID='"&UserID&"'"
newconn.Execute(newsql2)
Application(UserID)="??ò??-??è?á?·???"&newroom&"<br>"&Application(UserID)
session("myroom")=newroom

changed=true
newrecord1.Close
set newrecord1=nothing
end if
case "/r"
newsql="select * from RoomInfo"
set newrecordset1=newconn.Execute(newsql)
do while not newrecordset1.eof
info=info & newrecordset1("RoomName")& "--" & newrecordset1("HowManyUsers") & "--" & newrecordset1("Topic") & "--" & newrecordset1("IfLocked") & "--" &newrecordset1("WhoCreate") & "<br>"
newrecordset1.movenext
loop
Application(UserID)=info &"<br>" &Application(UserID)
case "/w"
if len(trim(Request.Form("T1")))=2 then
newsql="select * from UserOnLine"
set newrecordset2=newconn.Execute(newsql)
do while not newrecordset2.eof
info=info&newrecordset2("UserId")&"--"&newrecordset2("RoomName")&"--"&newrecordset2("IpAdd")&"--"&newrecordset2("TimeLogin")&"<br>"
newrecordset2.movenext
loop
Application(UserID)=info&"<br>"&Application(UserID)
else
if right(left(Request.Form("T1"),3),1)<>":"then
info="?üá?DDê?è?′í?ó<br><br>"
Application(UserID)=info & Application(UserID)
else
temproom=mid(trim(Request.Form("T1")),4)
newsql="select RoomName from RoomInfo where RoomName='"&temproom&"'"
set newrecord3=newconn.Execute(newsql)
if not newrecord3.bof then
newsql="select * from UserOnLine where RoomName='"&temproom&"'"
set newrecordset2=newconn.Execute(newsql)
if newrecordset2.bof then
Application(UserID)="<br>??·????Yê±??óDè?!<br><br>"&Application(UserID)
else
do while not newrecordset2.eof
info=info&newrecordset2("UserID")&"--"& newrecordset2("RoomName")&"--"&newrecordset2("IpAdd")&"--"&newrecordset2("TimeLogin")&"<br>"
newrecordset2.movenext
loop
Application(UserID)="<br>"&info&"<br>"&Application(UserID)
end if
else
info="<br>??óD<font color=vbred><strong>"&temproom&"</strong></font>?a??·???£?<br><br>"
Application(UserID)=info&Application(UserID)
end if
end if
end if
case "/1"
newsql="select WhoCreate from RoomInfo where WhoCreate='"&UserID&"'and RoomName='"&session("myroom")&"'"
set newrecordset=newconn.Execute(newsql)
if newrecordset.bof then
Application(UserID)="2?o?òa??£????Tè¨??×??a??·???£?<br><br>"&Application(UserID)
else
newsql="update RoomInfo set IfLocked=true where RoomName='"&session("myroom")&"'"
newconn.Execute(newsql)
Application(UserID)="??ò??-??×?á??a??·???!<br><br>"&Application(UserID)
end if
case "/u"
newsql="select WhoCreate from RoomInfo where WhoCreate='"&UserID&"'and RoomName='"&session("myroom")&"'"
set newrecordset=newconn.Execute(newsql)
if newrecordset.bof then
Application(UserID)="2?o?òa??£????Tè¨?a?a?a??·????ò??2??ú????·???£?<br><br>"&Application(UserID)
else
newsql="update RoomInfo set IfLocked=false where RoomName='"&session("myroom")&"'"
newconn.Execute(newsql)
Application(UserID)="??ò??-?a?a?a??·???£?<br><br>"&Application(UserID)
end if
case "/c"
Application(session("myname"))=""
case "/b"
%>
<script language="javascript">
<!--
//è?ò3????è?byebye.asp
top.location.href="byebye.asp"
//-->
</script>

<%
session.Abandon
Response.End
case"/h"
info="/h---3???°??úìáê?<br>"
info=info&"/j:roomname---?óè?D?μ?·???<br>"
info=info&"/r--2é?′μ±?°·???D??¢<br>"
info=info&"/w:roomname---2é?′μ±?°ó??§?é??<br>"
info=info&"/l--??×?μ±?°·???£???óD′′?¨??2??ü??×?<br>"
info=info&"/b--í?3?á?ììêò<br>"
info=info&"/u--?a?a?3??·???<br>"
info=info&"/t:newtopic--DT???°ìa£???óD′′?¨??2??üDT??<br>"
info=info&"/c--??3yá?ìì?úèY<br>"
Application(UserID)="<br>"&info&"<br>"&Application(UserID)
case"/t"
if right(left(command,3),1)<>":"then
Application(UserID)="<br>?üá?ê?è?′í?ó£?<br><br>"&Application(UserID)
else
newsql="select WhoCreate from RoomInfo where WhoCreate='"&UserID&"'and RoomName='"&session("myroom")&"'"
set newrecordset=newconn.Execute(newsql)
if newrecordset.bof then
Application(UserID)="2?o?òa??£????Tè¨DT???a??·???μ??°ìa£?<br><br>"&Application(UserID)
else
newsql="update RoomInfo set Topic='"&mid(command,4)&"' where RoomName='"&session("myroom")&"'"
newconn.Execute(newsql)
newsql="select UserID from UserOnLine where RoomName='"&session("myroom")&"'"
set t_newrecordset=newconn.Execute(newsql)
do while not t_newrecordset.eof
Application(t_newrecordset(0))="·????°ìa±?DT???a<font color=vbpurplea>"&mid(command,4)&"</font>!<br><br>"&Application(t_newrecordset(0))
t_newrecordset.movenext
loop
t_newrecordset.close
set t_newrecordset=nothing
end if
end if
case else
Application(UserID)="<br>??óD?a???üá?,??ó?/h2é?′°??ú<br>"&Application(UserID)
end select
else
if request.Form("D1")<>"all" then

id_name=Request.Form("D1")
temppos=instr(1,id_name,",",1)
yourid=mid(id_name,1,temppos-1)
yournickname=mid(id_name,temppos+1)
end if
set myrecord=server.CreateObject("ADODB.Recordset")
mysql="select * from UserOnLine where RoomName='"&myroom&"'"
myrecord.Open mysql,"DSN=ChatRoom",1,3
if request.Form("D1")="all" or request.Form("C1")<>"ON" then
if request.Form("D1")="all" then
tempstr="<font color='"&request.Form("D2") & "'>"&mynickname&Request.Form("facing")&"?μ£o"&request.Form("T1")&"</font><font color=blue size=0.5>("&time()&")</font><br>"
else
tempstr="<font color='"&request.Form("D2")&"'>"&mynickname&"????"&yournickname&Request.Form("facing")&"?μ£o"& request.Form("T1")&"</font><font color=blue size=0.5>("&time()&")</font><br>"
end if
do while not myrecord.EOF
Application(myrecord("UserID"))=tempstr&Application(myrecord("UserID"))
myrecord.MoveNext
loop
Application(myroom)=tempstr&Application(myroom)
if len(Application(myroom))>1000 then
length2=len(Application(myroom))
temppos=instrrev(Application(myroom),"<br>",length2)-1
Application(myroom)=mid(Application(myroom),1,temppos)
end if
else
tempstr="<marquee border='0' behavior='alternate'><font color='"&request.Form("D2")&"'>"&mynickname&"??" &yournickname&Request.Form("facing")&"?μ:"&request.Form("T1")&"</font></marquee>"&"<font color=blue size=0.5>("&time()&")</font><br>"
Application(yourid)=tempstr&Application(yourid)
Application(myname)=tempstr&Application(myname)
end if
if len(Application(myname))>20000 then
length1=len(Application(myname))
temppos=instrrev(Application(myname),"<br>",length1-4)-1
Application(myname)=mid(Application(myname),1,temppos)
end if
Application.UnLock
end if
Response.Write Application(UserID)
else
Response.Write Application(UserID)
end if
newconn.Close
set newconn=nothing
'changed=true
if changed=true then
%>
<script language="javascript">
<!--
parent.frames[1].location.href="send.asp"
//-->
</script>
<%
end if
%>


</body>
</html>

[此贴子已经被作者于2006-2-10 18:16:41编辑过]

搜索更多相关主题的帖子: 乱码 Microsoft ASP content 
2006-02-10 18:16
阳光白雪
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:39
帖 子:2220
专家分:0
注 册:2005-11-18
收藏
得分:0 
字符集编码的原因,
content="text/html; charset=gb2312 就是指定字符编码,

专注于WEB前端交互平台开发:[url=http://blog./]blog.[/url](富客户端技术(RIA)交流平台)
2006-02-10 19:33
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
显示给用户的网页最好指定字符编码,而纯ASP代码的网页,可以不指定字符编码用记事本或来写。
2006-02-10 21:03
yourselsa
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-2-1
收藏
得分:0 

我的意思是为什么第一段代码中没有加入字符编码集gb2312却不显示成乱码呢?
谢谢啊感激不尽

[此贴子已经被作者于2006-2-10 22:07:39编辑过]


2006-02-10 22:05
水露
Rank: 1
等 级:新手上路
帖 子:143
专家分:0
注 册:2005-8-3
收藏
得分:0 
我有时也会出现这样的问题。只是你第二个出现乱码是必然的。 只是出现的时间是不一定的。 比如说代码写成功后不会出现乱码, 但运行一段时间就出现了乱码。。而你的第一个是永远不会出现乱码的。所以按照二楼说的是没错的。

2006-02-10 22:48
caiyakang
Rank: 2
等 级:新手上路
威 望:5
帖 子:2111
专家分:0
注 册:2005-3-24
收藏
得分:0 

应该是指定编码方式,
gb2312是中国的汉字标码
如果你不指定的话,系统有时会认为其他编码方式,
特别是,到国外空间!!


中国人的财富网:http://www..cn/
2006-02-10 22:58
yourselsa
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-2-1
收藏
得分:0 

如何指定编码方式呢?
第一段代码并没有写gb2312,是不是可以从其它的地方设定?


2006-02-10 23:36
快速回复:ASP代码中乱码问题的解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022151 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved