Java page URL Pass value Chinese garbled solution _java

Source: Internet
Author: User

The problem of Chinese is often encountered in the application.


This will involve character decoding operations, which we often use in the application of New String (Fieldtype.getbytes ("iso-8859-1"), "UTF-8"), and similar methods to decode it. But this way is limited by the specific application environment, often in the application deployment environment changes, will also appear in Chinese garbled.

Here is a workaround that can be used in any application deployment environment. This method is divided into two steps:

1, in the client with Escape (encodeURIComponent (Fieldvalue)) method encoding, for example:

Copy Code code as follows:

Title=escape (encodeURIComponent (title)); This is the function in JS.

Url= "<%=request.getcontextpath ()%>/print/printlist!printtable.action?title=" +title;


2, in the service End with Java.net.URLDecoder.decode (Getrequest () getparameter ("title"), "UTF-8"), to decode.

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

The garbled problem of SRC in Parent.window.location.href and iframe.

To pass Chinese in these two URL addresses, you must encode and then decode.

Encoding: encodeURI (encodeURI ("contains Chinese strings")

Decoding: Java.net.URLDecoder.decode ("strings 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.