“Encoding” is one of the most headache problem in a webapp. It alway goes with these kinds of files: java, javascript. And the cause is widely related to our system encoding, file encoding, idea encoding( development tool encoding, project encoding, javac encoding).
Initial file encoding:
Each file will get an encoding at its creation. This encoding is decided by the develpment tool. It always be one of UTF-8, GBK and ISO-8859.
garbled with javascript files
garbled: Some of your javascript files’ encoding is different with the project encoding that specified in idea [file encoding–>project encoding].
solve Change the [file encoding–>project encoding] same with the javascript files’ encoding.
console garbled
solve: [settings–>…–>maven–runner]jvm options: -Dfile.encoding=UTF-8
compile error with java files
example: unmappable character for encoding UTF-8.
error: Some of your java files’ encoding is different with javac encoding, it will goes with a compile error.
cause: The javac use an encoding to encode characters in java files when compileing them. The encoding is always the system encoding. But we can specify it at any where that will use javac, like maven plugin and tomcat plugin in idea. And we can also specify it at poms.
solve: When the error occured, find the file in idea and convert its encoding to the target encoding. You can also javac encoding. The rule is to ensure the two encodings same.