Solution to garbled characters when url is transmitted to Chinese in Java
I believe many friends have encountered the problem of garbled characters when transmitting Chinese to URL in Java. Recently, I encountered a problem, which is to bind a piece of Chinese information to the URL in Action. Later, when ActionForward goes to another page, garbled characters will appear when reqeust.getParameter is used to retrieve it.
Solution:
1. Encode the Chinese characters to be passed in the URL:
String message = java.net.URLEncoder.encode("中文字符","utf-8");
2. Decode the characters on the page where the URL passes Chinese characters:
String msg = request.getParameter("message"); String str=new String(msg.getBytes("ISO-8859-1"),"UTF-8");
Note:
1. The str obtained here is the "Chinese character" passed in previously.
2. Why should the extracted character set format be converted into UTF-8 format? This is because ISO-8859-1 is the standard character set used for network transmission in Java, request.getParameter("message"); What you get is still the ISO-8859-1 character set, so you need to convert it.
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Solution to garbled characters when url is transmitted to Chinese in Java. 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

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),

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

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

SublimeText3 Linux new version
SublimeText3 Linux latest version