选择显示字体大小

wap中文提交乱码问题解决办法探讨

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <%
  var description=request(&quot;description&quot;);
 %>

 <card>
  <br>
   测试:(<%=description%>)<br/>
   <input>
   <a href=&quot;test.asp?description=&#36;(description:e)&quot;>提交..</a><br/>
  </p>
 </card>
 
</wml> 


输入: 中文测试
结果显示: 涓枃娴嬭瘯
结果分析:字符变成utf-8编码,需要重新做utf-8 => gb2312的转换处理

示例2:文件以普通ansi编码方式保存

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <%
  var description=request(&quot;description&quot;);
 %>

 <card>
  <p>
   测试:(<%=description%>)<br/>
   <input>
   <anchor>提交..<go href=&quot;test.asp&quot;><postfield></go></anchor><br/>
  </p>
 </card>
 
</wml> 


输入: 中文测试
结果显示: %e4%b8%ad%e6%96%87%e6%b5%8b%e8%af%95
结果分析:这是对字符进行了encodeuri编码,只需要执行js方法decodeuri即可

注:以上示例表明用querystring和post还是有所区别的

示例3:文件以utf-8编码方式保存

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <%
  var description=request(&quot;description&quot;);
 %>

 <card>
  <p>
   &#x6d4b;&#x8bd5;:(<%=description%>)<br/>
   <input>
   <a href=&quot;test.asp?description=&#36;(description:e)&amp;operate=guestbook_save&quot;>&#x63d0;&#x4ea4;..</a><br/>
  </p>
 </card>
 
</wml> 


输入:中文测试
结果显示:中文测试
结果分析:因为文件用utf-8编码方式保存,所以接收端直接获得了utf-8的字符

示例4:

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <%
  var description=request(&quot;description&quot;);
 %>

 <card>
  <p>
   &#x6d4b;&#x8bd5;:(<%=description%>)<br/>
   <input>
   <anchor>&#x63d0;&#x4ea4;..<go href=&quot;test.asp&quot;><postfield></go></anchor><br/>
  </p>
 </card>
 
</wml> 


输入:中文测试
结果显示:%e4%b8%ad%e6%96%87%e6%b5%8b%e8%af%95
结果分析:因为提交时设置了进行escape转换,所以不受文件编码方式的影响

可是用anchor+go的方法写实在是有点浪费,a简洁的多,也更节省wml的字节数,那么就可以试试以下方法,文件以普通ansi编码方式保存

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <template>
  <do type=&quot;prev&quot; label=&quot;返回&quot;>
   <go href=&quot;#nav&quot;/>
  </do>
 </template>

 <%
  function unicode2gb(str,oldcharset,newcharset)&#123;
   var stream=new activexobject(&quot;adodb.stream&quot;)
   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;
  &#125;
  var t=new date();
  var description=string(request(&quot;description&quot;));

  description=unicode2gb(description,&quot;utf-8&quot;,&quot;gb2312&quot;);
 %>

 <card>
  <p>
   测试:(<%=description%>)<br/>
   <input>
   <a href=&quot;test.asp?description=&#36;(description:e)&amp;operate=guestbook_save&quot;>提交..</a><br/>
  </p>
 </card>
 
</wml>


输入:中文测试
结果显示:中文测试

或者你想用utf-8编码方式保存文件,那就这样

<%@language=&quot;javascript&quot; codepage=&quot;936&quot;%>
<% response.contenttype=&quot;text/vnd.wap.wml&quot; %>
 
<!doctype wml public &quot;-//wapforum//dtd wml 1.1//en&quot; &quot;http://www.wapforum.org/dtd/wml_1.1.xml&quot;> 

<wml>
 <head>
  
  
  
 </head>

 <template>
  <do>
   <go href=&quot;#nav&quot;/>
  </do>
 </template>

 <%
  function unicode2gb(str,oldcharset,newcharset)&#123;
   var stream=new activexobject(&quot;adodb.stream&quot;)
   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;
  &#125;
  var t=new date();
  var description=string(request(&quot;description&quot;));

  description=unicode2gb(description,&quot;utf-8&quot;,&quot;gb2312&quot;);

  description=description.replace(/[^\u0000-\u00ff]/g,function(&#36;0)&#123;return escape(&#36;0).replace(/(%u)(\w&#123;4&#125;)/gi,&quot;&#x&#36;2;&quot;)&#125;);
 %>

 <card>
  <p>
   &#x6d4b;&#x8bd5;:(<%=description%>)<br/>
   <input>
   <a href=&quot;test.asp?description=&#36;(description:e)&amp;operate=guestbook_save&quot;>&#x63d0;&#x4ea4;..</a><br/>
  </p>
 </card>
 
</wml>


输入:中文测试
结果显示:&#x4e2d;&#x6587;&#x6d4b;&#x8bd5;

以上代码由asp+js完成,因为js没有基于“位”的字符操作功能,所以借助了ado.stream来做了这个转换,希望能给大家一点帮助(当然,我知道大多数asp开发者都是习惯用vbs的)


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons