Java Code
-
- <%!PublicString gbtoiso (string Str)
-
- {Try{ByteTemp [] = Str. getbytes ("Gb2312");
-
- STR =NewString (temp,ISO-8859-1");
- ReturnSTR;
-
- }Catch(Exception e ){ReturnSTR ;}}
-
-
- Response. sendredirect (gbtoiso ("Errmsg. <SPAN class = hilite1> JSP </span>? Errmsg = customer information added"); %>
<%! Public String gbtoiso (string Str) {try {byte temp [] = Str. getbytes ("gb2312"); STR = new string (temp, "ISO-8859-1"); Return STR;} catch (exception e) {return STR ;}} response. sendredirect (gbtoiso ("errmsg.JSP? Errmsg = customer information added "); %>
In the hyperconnection, the priority sion isChinese
Java code
- <A href ="Cust_totallist. <SPAN class = hilite1> JSP </span>? Action = Delete & page = <% = intcurrentpage %> & cust_id = <% = Rs. getint ("ID") %> & Amp; customization sion = <% = java.net. <SPAN class = hilite2> URL </span> encoder. encode (partition Sion ,"Iso-8859-1") %>"> Delete </a>
-
- ///// // Cust_totallist. <SPAN class = hilite1> JSP </span>
- string compression sion = java.net. class = hilite2> URL decoder. decode (request. getparameter ( " regression Sion " ). trim (), " ISO-8859-1 " );
<A href = "cust_totallist.JSP? Action = Delete & page = <% = intcurrentpage %> & cust_id = <% = Rs. getint ("ID") %> & define sion = <% = java.net.URLEncoder. encode (plugin Sion, "ISO-8859-1") %> "> Delete </a> // cust_totallist.JSPReturns the string extension sion = java.net.URLDecoder. Decode (request. getparameter ("visibility Sion"). Trim (), "ISO-8859-1 ");
Visible,URLEncoding format in ISO-8859-1, processingChineseJust convert the encoding format to the ISO-8859-1
Method 1:
Http://xxx.do? Ptname = 'I am a China'
Java code
- String strptname = request. getparameter ("Ptname");
- Strptname =NewString (strptname. getbytes (ISO-8859-1"),UTF-8");
String strptname = request. getparameter ("ptname"); strptname = new string (strptname. getbytes ("ISO-8859-1"), "UTF-8 ");
Method 2:
Java code
- <% @ Page contenttype ="Text/html; charset = gb2312"%>
-
- <A href ="Ds. <SPAN class = hilite1> JSP </span>? <SPAN class = hilite2> URL </span> = <% = java.net. <SPAN class = hilite2> URL </span> encoder. encode ("It is encoded here","Gb2312") %>"> Click here </a>
-
- <%
-
- // Request. setcharacterencoding ("GBK ");
- If(Request. getparameter ("<SPAN class = hilite2> URL </span>")! =Null)
-
- {
-
- STR = request. getparameter ("<SPAN class = hilite2> URL </span>");
-
- STR = java.net. <SpanClass= Hilite2> URL </span> decoder. Decode (STR,"Gb2312");
- STR =NewString (Str. getbytes (ISO-8859-1"));
-
- Out. Print (STR );
-
- }
-
- %>
<% @ Page contenttype = "text/html; charset = gb2312" %> <a href = "Ds.JSP?URL= <% = Java.net.URLEncoder. encode ("encode here", "gb2312") %> "> click here </a> <% // request. setcharacterencoding ("GBK"); If (request. getparameter ("URL")! = NULL) {STR = request. getparameter ("URL"); STR = java.net.URLDecoder. Decode (STR, "gb2312"); STR = new string (Str. getbytes ("ISO-8859-1"); Out. Print (STR);} %>
Java code
- PublicString chinatostring (string Str)
-
- {
-
- String S = STR;
-
- Try
-
- {
-
- ByteTempb [] = S. getbytes (ISO-8859-1");
-
- S =NewString (tempb );
- ReturnS;
-
- }
-
- Catch(Exception E)
-
- {
-
- ReturnS;
-
- }
-
- }
Public String chinatostring (string Str) {string S = STR; try {byte tempb [] = S. getbytes ("ISO-8859-1"); s = new string (tempb); Return s;} catch (exception e) {return s ;}}
Java code
- Function <SpanClass= Hilite2> URL </span> encode (SSTR)
-
- {
-
- ReturnEscape (SSTR ).
-
- Replace (/\ +/g,'% 2B').
-
- Replace (/\ "/g,'% 22').
-
- Replace (/\'/G ,'%27').
- Replace (/\// G, '% 2f ');
-
- }
FunctionURLEncode (SSTR) {return escape (SSTR ). replace (/\ +/g, '% 2B '). replace (/\ "/g, '% 22 '). replace (/\ '/g,' % 27 '). replace (// G, '% 2f ');}
Method 3:
If jstl is used, you can write an El function and callURLEncoder. encode.
IE default pairURLThe following parameters are not encoded, but Tomat is performed by ISO8859-1 by default.URLTherefore, the above error occurs. A good practice is:
1.URLParameters to ensure that the use of UTF-8 encoding, the method can use JS functions encodeuri (), or call the custom El function;
2. Set connector in server. XML to familiarize themselves with uriencoding = "UTF-8" to ensure that the decoding format is consistent with the encoding format;
Method 4:
XML Code
-
- <Script>
- For (VARI=0; I<Document. Links. Length; I ++ ){
-
- Document. Links [I]. Href=Encodeuri(Document. Links [I]. href );
-
- }
-
- </Script>
<SCRIPT> for (VAR I = 0; I <document. links. length; I ++) {document. links [I]. href = encodeuri (document. links [I]. href) ;}</SCRIPT>
In action, string S = request. getparameter ("S ");
S = new string (S. getbytes ("iso-8859-1"), "GBK ");
The above method is to collect the solutions mentioned by some netizens.