Reason:
The browser views the ISO8859-1 code table submission data by default.
Solution:
1. If the submission method is post, you only need to set the encoding of the request object if you want to avoid garbled characters.
Note: Which way the client data is submitted, the request should be set to what encoding.
2. If the submission method is get, setting the encoding of the request object is invalid. If you want to avoid garbled characters, you can only convert it manually.
String data = "???????";//乱码字符串 byte source [] = data.getBytes("iso8859-1");//得到客户机提交的原始数据 data = new String (data.getBytes("iso8859-1"),"UTF-8");//解决乱码 //等同于data = new String (source,"UTF-8");
Recommended tutorial: Java tutorial
The above is the detailed content of Garbled characters appear when submitting data via form in java using post method. For more information, please follow other related articles on the PHP Chinese website!