Java Chinese garbled problem

Source: Internet
Author: User

Two types of problems encountered by the Java platform:

1. Source code Chinese garbled problem:

A.java file, Chinese garbled, configure the IDE's preference encoding format, there is always a suitable for you.

B.html (JSP 、.... ) file, Chinese garbled, add and set the HTML contenttype, CharSet can be. <%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>

2. Input Chinese garbled problem in the application:

A.selvert filter to handle Chinese garbled problem:

Modify the configuration parameters in Web. xml:

<filter> <!--Note This is filter, do not configure it as servlet-->
<filter-name>CharactorFilter</filter-name> <!--filter Name--
<filter-class>cn.com.Filter.CharactorFilter</filter-class> <!--filter's full class name--
<init-param> <!--initialization Parameters--
<param-name>encoding</param-name> <!--parameter name---
<param-value>utf-8</param-value><!--parameter Values--
</init-param>
</filter>
<filter-mapping> <!--filter Map--
<filter-name>CharactorFilter</filter-name><!--Filter Name--
<url-pattern>/*</url-pattern><!--URL mapping to handle all pages garbled---
</filter-mapping>

B.tomcat support for Chinese configuration issues: Change the Tomcat installation directory under Conf\server.xml, specify the browser's encoding format as "Simplified Chinese":

<connector port= "8080" maxthreads= "75" minsparethreads= "maxsparethreads="
Enablelookups= "false" redirectport= "8443" acceptcount= "100"
connectiontimeout= "20000" disableuploadtimeout= "true" uriencoding= ' GBK ' />

Note: The Chinese parameter of the Spring MVC controller parsing The Get method is garbled: the Spring filter only filters the HTTP POST method, and the Get method is not processed, so the configuration filter is not valid anyway. Therefore, you can only go back to the first layer, that is, from the Web application container layer to the Tomcat layer configuration Server.xml connector urieconding= "UTF-8" attribute.

Java Chinese garbled problem

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.