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.