Java page url value Chinese garbled code solution

  • 2020-04-01 01:27:29
  • OfStack

Chinese problem, is often encountered in the application of the problem.


This will involve character decoding operations, we often use new String(fieldtype.getbytes ("iso-8859-1"), "utf-8 "); Or something like that. But this way is limited by the specific application environment, often in the application deployment environment changes, there will be Chinese garbled code.

Here is a solution that can be used in any application deployment environment. This method consists of two steps:

1. Use the escape(encodeURIComponent(fieldValue)) method on the client side, for example:


title=escape(encodeURIComponent(title)); //This is a function in js
url="<%=request.getContextPath()%>/print/printList!printTable.action?title="+title;

2, on the server with java.net.URLDecoder.decode (getRequest (). The getParameter (" title "), "utf-8"), and decoding.

-----------------------------------------------------------------------------

. The parent window. The location. The href and iframe SRC gibberish.

To transmit Chinese in these two url addresses, you must add the encoding, and then decode.

EncodeURI (encodeURI(" string containing Chinese "))

Decoding: java.net.URLDecoder.decode (" need to decode the string ", "utf-8");


Related articles: