For Post requests, you can solve the problem of Chinese garbled code passed from the form by simply writing the following code in Servlet or jsp
request.setCharacterEncoding("utf-8");
For Get requests, since the request parameters will be attached to the URL in the address bar, the above processing method cannot be used. It should be like this:
String str=request.getQueryString();//Use URLDecoder to decode the string String str1=java.net.URLDecoder.decode(str,"utf-8");String[] paraStrings=str1.split("&");//paraStrings[0] is the first parameter, and so on...for(String paraString : paraStrings){ String[] nameValue=paraString.split("="); //nameValue[0] is the name of the form, and nameValue[1] is the value corresponding to the form name} Another method is to obtain the request parameters and then re-encode the request parameter value, that is, convert it into a byte array, and then re-decode the byte array into a string.
String str=request.getParameter("name");byte[] bytes=str.getBytes("ISO-8859-1");String name=new String(bytes,"utf-8");The above article perfectly solves the problem of Chinese garbled code in Get and Post requests. This is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.