The solution to the garbled code submitted to tomcat on the page is to configure it in tomcat/conf/server.xml (recommended: java video tutorial)
Taking tomcat6.0.32 as an example, you need to change the following code:
Xml code
<Connectorport="8080"protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
to:
Xml code
<Connectorport="8080"protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"URIEncoding="UTF-8"/> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
If If the tomcat front-end has Apache or Nginx forwarding, you need to change:
Xml code
<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
to:
Xml code
<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"URIEncoding="UTF-8"/> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
Chinese url garbled code Here is a solution that can be used in any application deployment environment. This method is divided into two steps:
1. Use the escape(encodeURIComponent(fieldValue)) method to encode on the client, for example:
title=escape(encodeURIComponent(title)); //这是js里的函数 url="<%=request.getContextPath()%>/print/printList!printTable.action?title="+title;
2. Use java.net.URLDecoder.decode on the server (getRequest().getParameter("title"),"UTF-8"), decode.
To transmit Chinese in these two URL addresses, you must encode and then decode.
编码:encodeURI(encodeURI("包含中文的串")) 解码:java.net.URLDecoder.decode("需要解码的串","utf-8");
JSP page garbled characters usually just need to specify the character set encoding at the beginning of the page using the following code. If it still doesn't work, then please use the following sentence to convert
str=new String(str.getBytes("ISO-8859-1"),"页面编码方式");
The encoding used by JAVA in network transmission is "ISO-8859-1", so it needs to be converted when outputting, such as:
String str=new String(str.getBytes("开发环境编码"),"ISO-8859-1");
To correctly display the Chinese after network encoding on the page, it must be similar to
Stirng str=new String(str.getBytes("ISO-8859-1"),"开发环境编码");
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java page garbled solution. For more information, please follow other related articles on the PHP Chinese website!