Chinese garbled characters on java pages

Source: Internet
Author: User

 

The Code is as follows:  

<Connectorport = "8080" protocol = "HTTP/1.1"
ConnectionTimeout = "20000"
RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>
<Connector port = "8080" protocol = "HTTP/1.1"
ConnectionTimeout = "20000"
RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>

Changed:

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 also need:

The Code is as follows:  

Xml Code
<Connectorport = "8009" protocol = "AJP/1.3" redirectPort = "8443"/>
<Connector port = "8009" protocol = "AJP/1.3" redirectPort = "8443"/>

Changed:

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 characters here 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:

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

To transmit Chinese Characters in these two URLs, the url must be encoded and decoded.

The Code is as follows:  

Encoding: encodeURI ("string containing Chinese characters "))
Decoding: java.net. URLDecoder. decode ("the string to be decoded", "UTF-8 ");

JSP page garbled characters generally only need to use the following code to specify character set encoding at the beginning of the page. If not, use the following sentence for conversion.

The Code is as follows:  

Str = new String (str. getBytes ("ISO-8859-1"), "page encoding method ");

JAVA is used in network transmission encoding is "ISO-8859-1", so in the output need to be converted, such:

The Code is as follows:  

String str = new String (str. getBytes ("Development Environment Code"), "ISO-8859-1 ");

The Network-Encoded chinese character must be similar

The Code is as follows:  

Stirng str = new String (str. getBytes ("ISO-8859-1"), "Development Environment encoding ");

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.