In ECLIPSE+MYECLIPSE+TOMCAT development, the global encoding is set to UTF-8 __ encoding

Source: Internet
Author: User
Tags stub

In Eclipse+myeclipse development, the global encoding is set to UTF-8

In the use of Eclipse+myeclipse development, many file encodings are iso-8859-1 by default and do not support Chinese (such as common JSP). So every time we build a file to manually change the code, in fact, we can set the file default encoding, in the future to create the next time we do not have to modify the code,

UTF-8

If you want to enable plug-in development applications to have better internationalization support, to maximize the support of Chinese output, it is best to make Java files using UTF-8 encoding. However, the default character encoding for the Eclipse workspace (workspace) is the operating system default encoding, and the default encoding for the Simplified Chinese operating system (Windows XP, Windows 2000 Simplified Chinese) is GB18030, The engineering code established in this workspace is GB18030, and the Java file created in the project is GB18030. If you want to make the new project, Java files directly to the UTF-8 you need to do the following:

1, Windows->preferences ... Open the Preferences dialog box, the left navigation tree, navigate to General->workspace, right text file encoding, select Other, change to UTF-8, and later create a new project. text file in its Properties dialog box Encoding is the UTF-8.

2, Windows->preferences ... Open the Preferences dialog box, navigate to the left navigation tree, navigate to General->content Types, the right context Types tree, click each subkey in the text, and enter "UTF-8" in the, point update!

Other Java application development related files such as properties, XML, etc. have been specified by the Eclipse default, respectively, Iso8859-1,utf-8, such as in the development of the need to change the encoding format can be specified here.

3, Window-->preference-->myeclipse-->files and Editors, change the "Encoding" of each subkey to "ISO 10645/unicode (UTF-8)", Dot apply!

4, after the above three steps, the new Java file is UTF-8 encoding, Eclipse compile, run, Debug is no problem, but do rcp application of product output, or plug-in output, it is always wrong, or can not compile through (the output to be compile), Or the output of the plug-in run when the Chinese display garbled. At this point need to RCP application, or plug-in plugin engineering build.properties Add a line, javacdefaultencoding ... = UTF-8. UTF-8 encoding when the output is compiled to know the Java source file. This setting requires that all Java source files be UTF-8 encoded and, if not all, referenced in Eclipse Help (Plug-in Development environment Guide > Reference > Feature and Plug-in build configuration), it is recommended that all Java source files be UTF-8 encoded.

If plug-in development, RCP application development originally based on other coding, such as GB18030, want to convert to UTF-8, then first, do the above; then convert the original encoding to UTF-8 encoding by looking up the encoding conversion tool, such as the ICONV based bulk conversion tool, and note that only Java source files are converted. Other types of files may already be a more appropriate encoding, the original project properties of the Text file encoding, from the original code to UTF-8 can be changed.

MyEclipse Encoding Settings
My myeclipse after the installation of the code defaults is GB18030, outside the general recommendation of the people with UTF-8. If the garbled behavior is found after the project is imported, the encoding settings are not set.

Global encoding Settings: Encoding settings method: Toolbar-->window-->preferences-->general-->workspace-->text file encoding, set the appropriate encoding.

Local Coding settings: In the Source right button-->general-->editors-->test editors-->spelling-->encoding, here is to set the encoding of a single file.

It is recommended that you use the global encoding settings.

For your safety, please only open the source of a reliable URL

Open site cancellation from: http://hi.baidu.com/mjsong07/blog/item/b56444fba0dde52e4e4aea1d.html write down the record in case of being garbled in the future 1 database: Select Character set when installing, Select the same character set when you create a new database. 2 JSP Pages: <%@ page contenttype= "text/html; Charset=utf-8 "%> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 ">charset consistent 3 servlet: Add Resp.setcontenttype (" Text/html;charset=utf-8 ") inside Dopost (); 4 Tomcat: Set as follows in Server.xml: Add bold text content
<connector port= "8080" maxthreads= "minsparethreads=" maxsparethreads= "75"
Enablelookups= "false" redirectport= "8443" acceptcount= "0" debug= "
connectiontimeout= "20000" disableuploadtimeout= "true" uriencoding= "UTF-8"/>
5 Add Filter: public class Encodingfilter implements filter {public void Destroy () {
TODO auto-generated Method Stub}
/**
* Program garbled processing work
* @param arg2: Filter chain, multiple filter components
*/
public void Dofilter (ServletRequest arg0, Servletresponse arg1,
Filterchain arg2) throws IOException, Servletexception {
HttpServletRequest request= (httpservletrequest) arg0;
Character set encoding of the data submitted in the request
Request.setcharacterencoding ("UTF-8");
Continue the request to a subsequent filter or servlet for processing
Arg2.dofilter (arg0, arg1);
} public void init (Filterconfig arg0) throws Servletexception {
TODO auto-generated method stub} config file: <filter>
<filter-name>encoding</filter-name>
<filter-class>common. Encodingfilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> Follow-up if there are found to continue ~ ~ Toss a slip, garbled but clouds.

Related Article

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.