When "get" is used, the captured page is appended with the encoding type
Copy codeThe Code is as follows:
<%
Server: servletactioncontext. getresponse (). setcharacterencoding ("UTF-8 ");
Client webpage special effect p/jsp.html target = _ blank> jsp Tutorial: <% @ page language = "java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%>
Response. expires =-9999
Response. addheader "pragma", "no-cache"
Response. addheader "cache-ctrol", "no-cache"
Response. addheader "content-type", "text/html; charset = gb2312" 'is the focus, otherwise garbled
Response. write "Chinese characters" %>
2. vbscript is used to solve the encoding problem when post is used:
The source code is as follows:
Copy codeThe Code is as follows:
<Script language = "vbscript">
Function urlencoding (vstrin)
Strreturn = ""
For I = 1 to len (vstrin)
Thischr = mid (vstrin, I, 1)
If abs (asc (thischr) <& hff then
Strreturn = strreturn & thischr
Else
Innercode = asc (thischr)
If innercode <0 then
Innercode = innercode + & h10000
End if
Hight8 = (innercode and & hff00) & hff
Low8 = innercode and & hff
Strreturn = strreturn & "%" & hex (hight8) & "%" & hex (low8)
End if
Next
Urlencoding = strreturn
End function
Function bytes2bstr (vin)
Strreturn = ""
For I = 1 to lenb (vin)
Thischarcode = ascb (midb (vin, I, 1 ))
If thischarcode <& h80 then
Strreturn = strreturn & chr (thischarcode)
Else
Nextcharcode = ascb (midb (vin, I + 1, 1 ))
Strreturn = strreturn & chr (clng (thischarcode) * & h100 + cint (nextcharcode ))
I = I + 1
End if
Next
Bytes2bstr = strreturn
End function
</Script>
The following uses the vbscript function:
Copy codeThe Code is as follows:
<Script language = webpage Effect>
/**
* Initialize an xmlhttp object
*/
Function initajax ()
{
Var ajax = false;
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("microsoft. xmlhttp ");
} Catch (e ){
Ajax = false;
}
}
If (! Ajax & typeof xmlhttprequest! = 'Undefined '){
Ajax = new xmlhttprequest ();
}
Return ajax;
}
Function saveuserinfo ()
{
Var msg = document. getelementbyid ("msg ");
Var f = document. user_info;
Var username = f. user_name.value;
Var userage = f. user_age.value;
Var usersex = f. user_sex.value;
Var url = "save. asp tutorial ";
Var poststr = urlencoding ("user_name =" + username + "& user_age =" + userage + "& user_sex =" + usersex); // use encoding for post
Var ajax = initajax ();
Ajax. open ("post", url, true );
Ajax. setrequestheader ("content-type", "application/x-www-form-urlencoded ");
Ajax. send (poststr );
Ajax. onreadystatechange = function (){
If (ajax. readystate = 4 & ajax. status = 200 ){
Msg. innerhtml = bytes2bstr (ajax. responsebody); // decoded upon retrieval
}
}
}
</Script>
<Form name = "user_info">
Name: <textarea name = "user_name"/> </textarea> <br/>
Age: <input type = "text" name = "user_age"/> <br/>
Gender: <input type = "text" name = "user_sex"/> <br/>
<Input type = "button" value = "Submit Form" onclick = "saveuserinfo ()">
</Form>
<Div id = "msg"> </div>
Successful