The Chinese problem is a problem often encountered in applications.
This will involve character decoding operations. In our applications, we often use new String(fieldType.getBytes("iso-8859-1"), "UTF-8"); and other similar methods to decode. However, this method is limited by the specific application environment, and Chinese garbled characters often appear when the application deployment environment changes.
Here is a solution that can be used in any application deployment environment. This method has two steps:
1. Use the escape(encodeURIComponent(fieldValue)) method to encode on the client, for example:
Copy the code code as follows:
title=escape(encodeURIComponent(title)); //This is a function in js
url="<%=request.getContextPath()%>/print/printList!printTable.action?title="+title;
2. Use java.net.URLDecoder.decode(getRequest().getParameter("title"),"UTF-8") on the server to decode.
-------------------------------------------------- --------------------------
The problem of garbled characters in parent.window.location.href and src in iframe.
To transmit Chinese in these two URL addresses, you must encode and then decode.
Encoding: encodeURI(encodeURI("String containing Chinese"))
Decoding: java.net.URLDecoder.decode("String to be decoded", "utf-8");