How to solve Chinese garbled characters in url passing of java pages

Source: Internet
Author: User

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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.