Page garbled
The reason for this garbled is that the character set encoding should not be specified for use in the page: just specify the character set encoding in the beginning of the page with the following code
The code is as follows |
|
<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.sql.*" errorpage= "err.jsp"%> |
Database garbled
This garbled will make you insert the database into garbled Chinese, or read out the display is garbled,
The workaround is as follows:
To add a coded character set to the database connection string
The code is as follows |
|
String url= "jdbc:mysql://localhost/digitgulf?user=root&password=root&useunicode=true& characterencoding=gb2312 "; |
and use the following code in the page:
The code is as follows |
|
Response.setcontenttype ("text/html;charset=gb2312"); Request.setcharacterencoding ("gb2312"); |
URL Pass Value garbled
Method One:
1. In b.jsp, replace pageencoding= "GB2312" with pageencoding= "Iso8859-1"
Although this b.jsp page display content or garbled, but not the kind of "??????" The garbled, but some special characters
2. Then in the browser to see the menu modified into GB2312 code, then garbled display in Chinese.
3. However, this method is not feasible.
Method Two:
1. In the b.jsp
The code is as follows |
|
String name=request.getparameter ("name"); |
Amended to
The code is as follows |
|
String Name=new string (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "GB2312"); |
2. Then the display on the page, it is Chinese.
Method Three:
The request parameter on the request page needs to be encodeURI, and then a character set conversion is required on the page receiving the request. The character set of the request and receive pages in this example is UTF-8:
1. The requested JSP page uses the JavaScript encodeURI () method to transfer the parameter to the code:
The code is as follows |
|
function Toview (param) { var encodeparam = encodeURI (param); window.location.href= "/naias/advana_form.do?method=showdetail&title=" +encodeparam; } |
2. Character set conversion in the action of a jump: www.111cn.net
The code is as follows |
|
Public Actionforward Excute (actionmapping mapping, actionform form, httpservletrequest request, HttpServletResponse Response) { String title= request.getparameter ("title"); title= New String (Title.getbytes ("iso-8859-1"), "UTF-8"); System.out.println (title); } |
For the code for UTF-8 JSP page parameters, for Chinese garbled solution is divided into two situations:
1. Pass through a Get method
The code is as follows |
|
New String (Request.getparameter (""). GetBytes ("Iso-8859-1"), "UTF-8"); |
The way to convert to the desired encoding, such as UTF-8.
2. Through the post way to pass the argument by declaration
code as follows |
|
request.setcharacterencoding ("UTF-8"); |