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

Implementation of select multiple data loading optimization in Element

Table of contents Scenario Code Implementation Su...

Do you know how to use Vue to take screenshots of web pages?

Table of contents 1. Install html2Canvas 2. Intro...

CSS3 Tab animation example background switching dynamic effect

CSS 3 animation example - dynamic effect of Tab b...

Canvas draws scratch card effect

This article shares the specific code for drawing...

In-depth analysis of Linux NFS mechanism through cases

Continuing from the previous article, we will cre...

Realize three-level linkage of year, month and day based on JavaScript

This article shares the specific code for JavaScr...

Mysql 5.6 "implicit conversion" causes index failure and inaccurate data

background When performing a SQL query, I tried t...

Solution to interface deformation when setting frameset height

Currently I have made a project, the interface is ...

Some notes on installing fastdfs image in docker

1. Prepare the Docker environment 2. Search for f...

How to preview pdf file using pdfjs in vue

Table of contents Preface think Library directory...

How to communicate between WIN10 system and Docker internal container IP

1. After installing the Windows version of Docker...

HTML table_Powernode Java Academy

To draw a table in HTML, use the table tag tr me...

How to export CSV file with header in mysql

Refer to the official document http://dev.mysql.c...

JavaScript ES new feature block scope

Table of contents 1. What is block scope? 2. Why ...

Write a mysql data backup script using shell

Ideas It's actually very simple Write a shell...