Java page Chinese garbled

Source: Internet
Author: User

The code is as follows

<connectorport= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/>
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/>

To

XML code
<connectorport= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "UTF-8"/>
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "UTF-8"/>

If the Tomcat front-end has Apache or Nginx forwarding, you will also need to:

The code is as follows

XML code
<connectorport= "8009" protocol= "ajp/1.3" redirectport= "8443"/>
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>

To

XML code
<connectorport= "8009" protocol= "ajp/1.3" redirectport= "8443" uriencoding= "UTF-8"/>
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443" uriencoding= "UTF-8"/>

================

Chinese URL 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:

The code is 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.

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

The code is as follows

Encoding: encodeURI (encodeURI ("contains Chinese strings")
Decoding: Java.net.URLDecoder.decode ("strings to be decoded", "Utf-8");

JSP page garbled usually only in the beginning of the page with the following code to specify the character set encoding can be. If not, please use the following sentence to convert

The code is as follows

Str=new String (str.getbytes ("iso-8859-1"), "page encoding Mode");

Java is used in the network transmission code is "iso-8859-1", so the output needs to be transformed, such as:

The code is as follows

String Str=new string (str.getbytes ("Development Environment Code"), "iso-8859-1");

After the network encoded Chinese, to correctly display on the page must be used similar to the

The code is as follows

Stirng str=new String (str.getbytes ("iso-8859-1"), "Development Environment Code");

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.