Home >Java >JavaBase >Garbled characters appear when submitting data via form in java using post method

Garbled characters appear when submitting data via form in java using post method

王林
王林Original
2019-11-16 10:46:092514browse

Garbled characters appear when submitting data via form in java using post method

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn