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

王林
Release: 2019-11-16 10:46:09
Original
2559 people have browsed it

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");
Copy after login

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 of this Website
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template