java garbled code under linux
Causes and solutions to garbled characters in Java language
a) Graphical interface program based on awt (swing) displays garbled characters in Chinese
In graphical interface programs based on awt (swing), the Chinese display in the menu will usually be garbled. The reason is generally that the JVM cannot find the font used to display Chinese. The JVM does not have a Chinese font under the original installation. , and the distribution versions of Linux are different, and the paths and names of their fonts are different, so the JVM generally cannot find the fonts included in the Linux operating system. The solution is to allow the JVM to find the fonts included in the Linux operating system. The font library that comes with it, such as under Redflag 6.0, can be solved by the following command:
1 2 |
|
Generally, there is no need to modify the font configuration file (fontconfig.OS.Version.properties) in the JRE/lib/ directory.
b) The system client browser based on B/S structure JSP (Servlet) displays garbled Chinese characters
The Chinese characters in the page display garbled characters
For static content like HTML file, the character set of the file only needs to be the same as the one set in the location in the file.
For dynamic files like JSP and Servlet, they need to be compiled. During operation, the JVM interprets the class file to generate the HTML file required by the client browser. If Chinese garbled characters are generated, it is usually compiled and run. generated during the process. If you use commercial Linux distributions and servers, you generally only need to save the JSP or Servlet file as the UTF-8 character set, and set Just set it to UTF-8. If garbled characters still appear, you can solve it by the following methods:
① If the server is independently developed, you can modify the source code to specify the JVM to read files, write files, and generate HTML files required by the client browser. , the encoding method when converting strings and binary sequence streams, thereby fundamentally solving the problem and enhancing the adaptability of the server. In MyWebServer 2.0, I adopted this method, and the code is as follows:
1 2 3 |
|
② Of course, you can also modify the "locale" setting of the JVM in the server's entry file (that is, the file containing the main subfunction). The code is as follows:
1 |
|
③ When using a commercial server, you can modify the shell file that starts the server , set the environment variable "export LC_ALL=zh_CN.UTF-8" before starting the server, thereby changing the default "locale" value under this console.
④ Of course, you can also modify the "locale" settings of the operating system, but since modifying the "locale" settings of the operating system will affect other applications, this method is generally used.
The main reason for using the above method is that when the JVM is started for the first time, the "locale" of the operating system will be set to the default "locale" of the JVM. When the "locale" value is not set in the operating system, The JVM will set the default "locale" of the JVM to the default "locale" of the JVM. Of course, you can also modify the default "locale" setting of the JVM when running the application. When the JVM converts strings to binary sequence streams, , if the encoding method is specified, it will be converted in the specified encoding method, otherwise it will be converted according to the default "locale" of the JVM.
Conclusion
The garbled characters generated by the Java language in Chinese display under Linux are mainly related to the JVM's font library, the locale settings of the operating system, the JVM's default locale settings, and the application The locale settings in and the binary sequence stream directly specified in the application are related to the character set for string conversion. It is due to the different character encoding methods used in the mutual conversion process of binary sequence streams and strings or the JVM cannot find the required font. Different methods can be used to solve it. The specific method to be used depends on the specific processing. Application Environment.
Recommended: [Linux Video Tutorial]
The above is the detailed content of java garbled code under linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.
