js| Solution | problem | chinese | Chinese garbled
In the process of using JSP, the most annoying problem is the Chinese garbled problem, the following is my software development encountered in the garbled problem and the solution.
1, JSP page garbled
The reason for this garbled is that the character set encoding should not be specified for use in the page, as long as you specify the character set code in the page at the beginning,
2, the database garbled
This garbled will make you insert the database into garbled Chinese, or read out the display is garbled, the solution is as follows:
To add a coded character set to the database connection string
String url= "jdbc:mysql://localhost/digitgulf?user=root&password=root&useunicode=true& characterencoding=gb2312 ";
and use the following code in the page:
Response.setcontenttype ("text/html;charset=gb2312");
Request.setcharacterencoding ("gb2312");
3, Chinese as a parameter transmission garbled
When we pass a paragraph of Chinese characters as a parameter to another page, there will be garbled situation, the solution is as follows:
The parameter is encoded when the parameter is passed, for example
Rearshres.jsp?keywords= "+ java.net.URLEncoder.encode (keywords)
Then use the following statement on the receive Parameters page to receive
Keywords=new String (request.getparameter ("keywords"). GetBytes ("8859_1"));
4, JSP page garbled add this sentence
<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.sql.*" errorpage= "err.jsp"%>