search
HomeJavaJavagetting StartedSummary on the problem of question marks and garbled characters in java

Summary on the problem of question marks and garbled characters in java

Nov 29, 2019 am 10:07 AM
javaGarbled charactersSummarize

Summary on the problem of question marks and garbled characters in java

In Java-based programming, we often encounter problems with the processing and display of Chinese characters, such as a lot of garbled characters or question marks.

This is because the default encoding method in JAVA is UNICODE, and the files and DBs commonly used by Chinese people are based on GB2312 or BIG5 and other codes, so this problem will occur. Below is a summary of such issues.

Free learning video sharing: java video

1. Output Chinese in the web page

JAVA is used in network transmission The encoding is "ISO-8859-1", so it needs to be converted when outputting, such as:

String str="中文";
str=new String(str.getBytes("GB2312"),"8859_1");

But when compiling the program, the encoding used is "GB2312 ", and if you run this program on a Chinese platform, this problem will not occur, so be sure to pay attention.

2. Read Chinese from parameters

This is exactly the opposite of outputting on the web page, such as:

str=new String(str.getBytes("8859_1"),"GB2312");

3. Operation DB Chinese problem in

A simpler method is: in the "Control Panel", set the "Region" to "English (United States)". If garbled characters still appear, you can also make the following settings:

When fetching Chinese:

str=new String(str.getBytes("GB2312"));

Input Chinese into DB:

str=new String(str.getBytes("ISO-8859-1"));

4. In jsp Chinese solution

In the "Control Panel", set the "Region" to "English (United States)".

Add in the JSP page:

If it is not displayed normally, the following conversion must be performed:

For example:

name=new String(name.getBytes("ISO-8859-1"),"GBK");

Then there will be no Chinese problem.

For more related articles and tutorials, please visit: java introductory tutorial

The above is the detailed content of Summary on the problem of question marks and garbled characters in java. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools