The garbled problem in Java EE and its solution the problem of __ garbled

Source: Internet
Author: User
Tags tomcat server

1, myeclipse default encoding settings.

To modify the encoding settings for all text files: windowsàpreference

To modify the encoding settings for the editor:

Here you can set the desired file type to UTF-8 (the encoding you need)

Finally, modify the encoding of the default project

So far, MyEclipse coding by default are the code you need, for the future will not be garbled problems to provide protection.

2, the servlet output in Chinese garbled problem

Servlet, the following statement has the foreground output garbled

Out.println ("Hello");

This is relatively simple, add in Dopost or Doget methods

Response.setcharacterencoding ("UTF-8");

Note that you must add to the output stream before

3, form submission of the Code

Post Submission Method

<formaction= "Servlet/codingservlet" method= "POST" >

<inputtype= "text" name= "id"/>

<inputtype= "Submit" value= "submitted"/>

</form>

In the servlet

String id = request.getparameter ("id");

OUT.PRINTLN (ID);

SYSTEM.OUT.PRINTLN (ID);

Console output: ...

Page output: Innocent

are garbled

Solution: Join request.setcharacterencoding ("UTF-8");

The console output is normal, the page is ...

Continue to join Response.setcharacterencoding ("UTF-8");

Garbled solution

Note: The above with the filter to write more convenient, but I have not learned, the temporary first so, learn will update up

Note: The above two statements must be written in front of the output stream, preferably in the first place of the method.

Get Submit Method

<formaction= "Servlet/codingservlet" method= "Get" >

<inputtype= "text" name= "id"/>

<inputtype= "Submit" value= "submitted"/>

</form>

Stringid = Request.getparameter ("id");

OUT.PRINTLN (ID);

SYSTEM.OUT.PRINTLN (ID);

Console:??? ¨¨??

Page: Hao by wipe

And all garbled, add two of Post's statement to solve the coding problem is invalid

Workaround:

Method begins by adding

Response.setcharacterencoding ("UTF-8");

And get the value in the following code:

String name1= request.getparameter ("name1");

String name = Newstring (Name1.getbytes ("iso-8859-1"), "UTF-8");

System.out.println ("------------------");

SYSTEM.OUT.PRINTLN (name);

OUT.PRINTLN (QQ);

Note: This garbled solution can also be modified Tomcat Server.xml file, but not recommended, because your project can not say in other servers run on garbled, so here omitted.

4, URL transfer value appears garbled.

The solution is the same as the form get method (in fact, the same way of submitting);

5, the MySQL garbled problem

Modify D:\soft\MySQL\MySQL Server 5.0 (your installation directory) My.ini files

Modify two places and reboot.

Garbled problem first written to this, in fact, this has solved most of the 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.