Preface
I believe many friends have encountered the problem of garbled code when passing Chinese URLs in Java. Recently, I encountered a problem, which is that when ActionForwards the Chinese information behind the URL, it is possible to use reqeust.getParameter to remove it. This is a problem of garbled code.
Solution
1. Encode the Chinese characters to be passed by URL:
String message = java.net.URLEncoder.encode("Chinese characters","utf-8");2. Decode characters on the page where the URL is passed in Chinese:
String msg = request.getParameter("message");String str=new String(msg.getBytes("ISO-8859-1"),"UTF-8");Notice:
1. The str obtained here is the "Chinese characters" that were previously passed in.
2. Why do I need to convert the extracted character set form to UTF-8? It is because ISO-8859-1 is the standard character set used for network transmission in Java, request.getParameter(“message”); ISO-8859-1 character set is still obtained, so I need to convert it.
Summarize
The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate.