search
HomeJavaJavaBaseJava question mark garbled solution

Java question mark garbled solution

Nov 27, 2019 am 09:15 AM
java

Java question mark garbled solution

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. (Recommended: java video tutorial)

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 encodings, so This problem occurs.

1. Output Chinese in the web page.

The encoding used by JAVA in network transmission 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 if the encoding is used when compiling the program, It 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 of Chinese problems in DB

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 getting Chinese: str=new String(str.getBytes("GB2312"));

Enter Chinese into the DB: str =new String(str.getBytes("ISO-8859-1"));

4. Chinese solution in jsp:

In the "Control Panel", change the "Area "Set to "English (United States)".

Add in the JSP page:

If it still cannot be displayed normally, the following conversion must be performed:

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

There will be no Chinese problem.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Java question mark garbled solution. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment