Recently developed a WAP system as a supplement to the original ASP SQLServer application registration code system. WAP uses WML than HTML strictly, bringing a lot of trouble to debug. More Chinese code issues, initially handled, and there are many detours.
One way to increase development is that first use the simulator to debug the WML file output from the program to complete the general structure development. WinWap is a good choice, which is used to initially debug or good, but it is different from the coding of the information submitted by the real mobile phone, and finally uses real mobile phones to complete the test.
WAP is also relatively simple in WAP, as long as the encoding mode is specified in the page, the Chinese can be displayed correctly. This is written in the code:
<% Response.contentType = "text / vnd.wap.wml" response.charset = "GB2312"%> XML Version = "1.0"?>
The WML page is such a writing submission information, where The input box will enter Chinese information:
However, Chinese submitted in the WAP browser is not GB2312 encoding, but UTF8 encoded. I found a conversion function UTF2GB from the Internet, it is also better, and the author is not marked in the author's name, thank the author thank you!
<% 'Use: Convert UTF-8 Code Chinese Characters to GB2312 Code, Compatible with English and Digital' Copyright: Although it is original, in fact, it also refers to some of the partial algorithms' usage: response.write UTF2GB ("% E9% 83% BD % E5% B8% 82% E6% 83% 85% E7% B7% A3% E6% 98% 9F% E5% ba% a7 ") Function UTF2GB (UTFSTR) on Error ResMe next for dig = 1 to Len (Utfstr) IF MID (Utfstr, Dig, 1) = "%" THEN IF LEN (Utfstr)> = Dig 8 Then GBSTR = GBSTR & Convchinese (MID (Utfstr, Dig, 9)) DIG = DIG 8 Else GBSTR = GBSTR & MID (Utfstr, DIG, 1) end if else gbstr = GBSTR & MID (Utfstr, DIG, 1) end if next if err.number <> 0 THEN UTF2GB = "" ELSE UTF2GB = GBSTR END IFEND FUNCTION
Function convChinese (x)
A = Split (MID (x, 2), "%") i = 0 j = 0
For i = 0 to Ubound (a) a (i) = C16TO2 (A (i)) Next
For i = 0 to Ubound (a) -1 DIGS = INSTR (A (i), "0") unicode = "" for j = 1 to DIGS-1 IF J = 1 THEN A (i) = Right (A (A (A) I), LEN (A (i)) - DIGS) Unicode = Unicode & A (i) ELSE I = i 1 A (i) = Right (A (i), LEN (A (i)) - 2) Unicode = Unicode & a (i) end if next
If LEN (C2to16 (Unicode)) = 4 Then ConvChinese = ConvChinese & Chrw (INT ("& H" = ConvChinese & Chr (int ("& H" & C2to16 (Unicode)) Endiff Next end function
Function C2TO16 (X) i = 1 for i = 1 to Len (x) Step 4 C2TO16 = C2TO16 & HEX (C2TO10 (MID (X, I, 4))) Next End Function
Function C2TO10 (X) C2TO10 = 0 IF x = "0" THEN EXIT FUNCTION END I = 0 for i = 0 to LEN (X) -1 IF MID (X, LEN (X) -i, 1) = "1 "THEN C2TO10 = C2TO10 2 ^ (i) Next End Function
Function C16TO2 (X) i = 0 for i = 1 to Len (Trim (x)) Tempstr = C10to2 (Cint (INT (INT ("& H" & MID (X, 1))))) DO While Len (Tempstr) < 4 Tempstr = "0" & Tempstr loop C16TO2 = C16TO2 & TEMPSTR NEXT END FUNCTIONFUNCTION C10TO2 (X) mysign = SGN (X) x = ABS (x) DIGS = 1 Do IF x <2 ^ DIGS TEN EXIT DO ELSE DIGS = 1 End if loop tempnum = x i = 0 for i = DIGS TO 1 Step-1 if Tempnum> = 2 ^ (i-1) TEMPNUM = Tempnum-2 ^ (i-1) C10to2 = C10to2 & "1" ELSE C10to2 = C10to2 & "0" end if next if mysign = -1 TEN C10to2 = "-" & C10to2 end if end "%>
During this function debugging process, discourse the Chinese coding information submitted by the 7610 mobile phone. The ASP's Request ("") object cannot be intercepted correctly, causing the UTF2GB function to report. At that time, I didn't expect to have problems here, waste a lot of time, and some GPRS fees! Finally, use the following functions to manually intercept the value in the request.form or Request.QueryString information, the problem is resolved:
Function getRequestValueByName (RequestStr, strName) 'extract html information submitted' input RequestStr, formats such as cmd = 3 & PHONETYPE_ID = 2 & APP_DESC =% e7% 9c% bc% e8% ae% 'value output strName of af, such strName = "cmd" is output 3 Const vbBinaryCompare = 0 'binary comparison Const vbTextCompare = 1' performs text comparison Dim searchBeginPos searchBeginPos = 1 posBegin = Instr (searchBeginPos, RequestStr, strName, vbTextCompare) If 0 = Int (posBegin) Then getRequestValueByName = "" Exit Function End IF posBegin = posBegin Len (strName) 1 searchBeginPos = posBegin posEnd = Instr (searchBeginPos, RequestStr, "&", vbTextCompare) IF Int (posEnd) = 0 Then posEnd = Len (RequestStr) 1 End IF iLen = Int (posEnd -posbegin) if Ilen <1 Then getRequestValuebyName = "" Else getRequestValueByName = MID (RequestStr, Posbegin, Posend-Posbegin) end if End function%> I don't know if I have encountered this situation, 7610, etc. committed Chinese information, ASP Reqest ("name") intercepts an error. M55 is normal.