Chinese problems are common problems in applications.
This involves the character decoding operation, we often use new String (fieldType. getBytes ("iso-8859-1"), "UTF-8"); and other similar methods to decode. However, this method is restricted by the specific application environment. When the application deployment environment changes, Chinese characters are garbled.
This section describes a solution that can be used in any application deployment environment. This method consists of two steps:
1. Use the escape (encodeURIComponent (fieldValue) method to encode the code on the client. For example:
Copy codeThe Code is as follows: title = escape (encodeURIComponent (title); // This is a function in js
Url = "<% = request. getContextPath () %>/print/printList! PrintTable. action? Title = "+ title;
2, in the server with java.net. URLDecoder. decode (getRequest (). getParameter ("title"), "UTF-8"), decoding.
-----------------------------------------------------------------------------
The src garbled characters in parent. window. location. href and iframe.
To transmit Chinese Characters in these two URLs, the url must be encoded and decoded.
Encoding: encodeURI ("string containing Chinese characters "))
Decoding: java.net. URLDecoder. decode ("the string to be decoded", "UTF-8 ");