Modify the jvm encoding problem when Tomcat is running

Modify the jvm encoding problem when Tomcat is running

question:

Recently, garbled data appeared when deploying the project. After checking, the project used the UTF-8 encoding format, and the data was also used. However, when it was transmitted to the other party through the calling interface, it was garbled.

Since it is deployed in a Windows environment, the default encoding of Windows is GBK, which leads to the problem of inconsistent encoding during JVM runtime, and it is also easy to modify.

Solution:

If you use UTF-8 encoding in Linux environment, you do not need to modify it, because Linux defaults to UTF-8

The war package is deployed in Tomcat

Modify jvm encoding

Linux Environment

Configuration in catalina.sh

JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=utf-8"

Since the default encoding format in Windows environment is GBK, you need to change the encoding format when Tomcat is running.

Windows Environment

Configuration in catalina.bat

set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8

If it is a jar package deployment, you only need to add the jvm parameter to the startup command.

JAR package deployment

Add jvm parameters to the startup command

java -Dfile.encoding=UTF-8 -jar xxx.jar

Summarize

The above is the editor's introduction to modifying the JVM encoding problem when running Tomcat. I hope it will be helpful to everyone!

You may also be interested in:
  • Detailed explanation of the difference between Java memory model and JVM runtime data area
  • Analysis of the JVM runtime data area principle
  • JVM: In-depth understanding of late (runtime) optimization
  • Detailed explanation of Java Virtual Machine (JVM) runtime
  • Detailed explanation of JVM runtime memory usage monitoring
  • JVM core tutorial: detailed explanation of the entire process of JVM operation and class loading
  • How to set JVM running parameters in IntelliJ IDEA
  • Detailed explanation of the principle of data area division at JVM runtime

<<:  Implementing calculator functions with WeChat applet

>>:  Example analysis of the page splitting principle of MySQL clustered index

Recommend

Suggestions on creating business HTML emails

Through permission-based email marketing, not onl...

Vue implements a movable floating button

This article example shares the specific code of ...

JavaScript data transmission between different pages (URL parameter acquisition)

On web pages, we often encounter this situation: ...

How to use axios to make network requests in React Native

In front-end development, there are many ways to ...

How to write the parent and child directories of HTML relative paths

How to indicate the parent directory ../ represent...

Solution to MySQL unable to read table error (MySQL 1018 error)

1. Error reproduction I can access the MySQL data...

About the problems of congruence and inequality, equality and inequality in JS

Table of contents Congruent and Incongruent congr...

Detailed example of changing Linux account password

Change personal account password If ordinary user...

How to use localStorage in JavaScript

If you are a developer looking to get into the wo...

Use CSS content attr to achieve mouse hover prompt (tooltip) effect

Why do we achieve this effect? ​​In fact, this ef...

In-depth analysis of nginx+php-fpm service HTTP status code 502

One of our web projects has seen an increase in t...

Nginx cache files and dynamic files automatic balancing configuration script

nginx Nginx (engine x) is a high-performance HTTP...

Detailed explanation of MySQL from getting started to giving up - installation

What you will learn 1. Software installation and ...