答案:示例1:文件以普通ansi编码方式保存
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<%
var description=Request("description");
%>
<card>
<br>
测试:(<%=description%>)<br/>
<input>
<a href=> </p>
</card>
</wml>
输入: 中文测试
结果显示: 涓枃娴嬭瘯
结果分析:字符变成UTF-8编码,需要重新做utf-8 => gb2312的转换处理
示例2:文件以普通ansi编码方式保存
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<%
var description=Request("description");
%>
<card>
<p>
测试:(<%=description%>)<br/>
<input>
<anchor>提交..<go href=> </p>
</card>
</wml>
输入: 中文测试
结果显示: %e4%b8%ad%e6%96%87%e6%b5%8b%e8%af%95
结果分析:这是对字符进行了encodeURI编码,只需要执行js方法decodeURI即可
注:以上示例表明用queryString和post还是有所区别的
示例3:文件以UTF-8编码方式保存
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<%
var description=Request("description");
%>
<card>
<p>
测试:(<%=description%>)<br/>
<input>
<a href=> </p>
</card>
</wml>
输入:中文测试
结果显示:中文测试
结果分析:因为文件用utf-8编码方式保存,所以接收端直接获得了UTF-8的字符
示例4:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<%
var description=Request("description");
%>
<card>
<p>
测试:(<%=description%>)<br/>
<input>
<anchor>提交..<go href=> </p>
</card>
</wml>
输入:中文测试
结果显示:%e4%b8%ad%e6%96%87%e6%b5%8b%e8%af%95
结果分析:因为提交时设置了进行escape转换,所以不受文件编码方式的影响
可是用anchor+go的方法写实在是有点浪费,a简洁的多,也更节省WML的字节数,那么就可以试试以下方法,文件以普通ansi编码方式保存
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<template>
<do type="prev" label="返回">
<go href=> </do>
</template>
<%
function unicode2gb(str,oldCharset,newCharset){
var stream=new ActiveXObject("ADODB.Stream")
stream.type=2
stream.Mode=0
stream.Open()
stream.Charset=newCharset
stream.WriteText(str)
stream.Position= 0
stream.Type= 2
stream.Charset=oldCharset
var s=stream.ReadText()
stream.Close()
return s;
}
var t=new Date();
var description=String(Request("description"));
description=unicode2gb(description,"utf-8","gb2312");
%>
<card>
<p>
测试:(<%=description%>)<br/>
<input>
<a href=> </p>
</card>
</wml>
输入:中文测试
结果显示:中文测试
或者你想用utf-8编码方式保存文件,那就这样
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<% Response.ContentType="text/vnd.wap.wml" %>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
</head>
<template>
<do>
<go href=> </do>
</template>
<%
function unicode2gb(str,oldCharset,newCharset){
var stream=new ActiveXObject("ADODB.Stream")
stream.type=2
stream.Mode=0
stream.Open()
stream.Charset=newCharset
stream.WriteText(str)
stream.Position= 0
stream.Type= 2
stream.Charset=oldCharset
var s=stream.ReadText()
stream.Close()
return s;
}
var t=new Date();
var description=String(Request("description"));
description=unicode2gb(description,"utf-8","gb2312");
description=description.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"$2;")});
%>
<card>
<p>
测试:(<%=description%>)<br/>
<input>
<a href=> </p>
</card>
</wml>
输入:中文测试
结果显示:中文测试
以上代码由asp+js完成,因为js没有基于“位”的字符操作功能,所以借助了ado.stream来做了这个转换,希望能给大家一点帮助(当然,我知道大多数asp开发者都是习惯用vbs的)
上一个:设计面向IE for Pocket PC的Web站点(六)
下一个:Servlet的decode函数可以解决奇偶问题