There are always some new users in the forum asking how to prevent Garbled text. It is convenient to write down and reply here ^_^
In fact, it is easy to configure three places to prevent garbled characters
1) Configure Tomcat server. xml; add uriencoding = "GBK"
<Connector Port = "8080" protocol = "HTTP/1.1" <br/> connectiontimeout = "20000" <br/> redirectport = "8443" uriencoding = "GBK"/>
2) configure the JSP page
<% @ Page Language = "Java" pageencoding = "GBK" %>
3) If you use servlet, you can add these two sentences to the filter, so that you do not need to write them every time.
You can add the following content in the doget () and dopost () Methods: <br/> request. setcharacterencoding ("GBK"); <br/> response. setcharacterencoding ("GBK"); </P> <p> You can also use the filter: <br/> <! -- Web. XML --> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <filter-class> COM. cl. filter. encodingfilter </filter-class> <br/> <init-param> <br/> <param-Name> encoding </param-Name> <br/> <param-Value> GBK </param-value> <br/> </init-param> <br/> </filter> </P> <p>/** encoding filter */ <br/> public class encodingfilter implements filter {<br/> private string encode = "GBK "; <br/> Public void Init (filterconfig config) throws servletexception {<br/> string GBK = config. getinitparameter ("encoding"); <br/> If (GBK = NULL | GBK. equals ("") {<br/> return; <br/>} else {<br/> encode = GBK; <br/>}</P> <p> Public void dofilter (servletrequest request, servletresponse response, <br/> filterchain chain) throws ioexception, servletexception {</P> <p> request. setcharacterencoding (encode); <br/> response. setcharacterencoding (encode); <br/> chain. dofilter (request, response); <br/>}< br/> Public void destroy () {<br/>}</P> <p>}
3) configure a constant for struts.
<Constant name = "struts. i18n. encoding" value = "GBK"/>
The configuration in the above three locations will not be garbled.
Encoding Problems in myeclipse from: http://zhidao.baidu.com/question/265299661.html
Myeclipse default encoding is GBK, JS file default encoding is ISO-8859-1. to utf8: 1. Windows-> preferences... open the "Preferences" dialog box, left navigation tree, navigate to general-> workspace, right text file encoding, select other, change to UTF-8, text file encoding in its properties dialog box is the UTF-8. 2. Windows-> preferences... open the "Preferences" dialog box, navigate to General> content types in the left navigation tree, select context types on the right, open text, and select Java source file, enter the UTF-8 in the following default encoding input box, and click Update to set the Java file encoding to UTF-8. Other files related to Java application development, such as properties and XML, have been specified by myeclipse by default, respectively for ISO8859-1, UTF-8, such as development needs to change the encoding format can be specified here. 3. After the above two steps, the new Java file is UTF-8 encoding, myeclipse compilation, running, debugging is no problem, but the RCP application product output, or plug-in output, there is always an error. Either the compilation fails (compile must be re-compiled during output), or the Chinese characters are garbled during the running of the output plug-in. Now you need to add a line in the build. Properties of the RCP application, or plug-in Plug-in project, javacdefaultencoding .. = UTF-8. Let the output compile know the UTF-8 encoding for the Java source file. This setting needs to ensure that all Java source files are in UTF-8 encoding format, if not all, you can refer to myeclipse help (plug-in development environment guide> reference> feature and plug-in build configuration), it is recommended that all Java source files are UTF-8 encoding. If the plug-in development, RCP application development based on other encoding, such as gb18030, want to convert to UTF-8, first, do the above work; then through the search encoding conversion tool, for example, based on the iconv batch conversion tool, convert the original encoding to UTF-8 encoding, note that only the conversion of Java source files, other types of files may already be more appropriate encoding; change text file encoding from the original project property to the UTF-8.