1.统一用UTF-8编码,即Tomcat的server.xml、页面、过滤器都用UTF-8
2.
请求参数,需要编码
<a href="newsAction?name=<%=java.net.URLEncoder.encode("表数据管理","UTF-8")%>"
target="frameset">Xls表数据管理 </a>
假如是java代码的话直接写java.net.URLEncoder.encode("测试吗","UTF-8");
下面引用Qieqie的一段代码:
- public static void main(String[] args) throws UnsupportedEncodingException {
-
- String src = "你好啊";
-
-
-
- byte[] bytes1 = src.getBytes("utf-8");
- System.out.println(bytes1.length);
-
-
-
-
-
-
- String temp = new String(bytes1, "gbk");
-
-
-
-
- byte[] bytes2 = temp.getBytes("gbk");
- System.out.println(bytes2.length);
- for (int i = 0; i < bytes1.length; i++) {
- System.out.print(bytes1[i] & 0xff);
- System.out.print("\t");
- }
- System.out.println();
- for (int i = 0; i < bytes2.length; i++) {
- System.out.print(bytes2[i] & 0xff);
- System.out.print("\t");
- }
- System.out.println();
-
-
- String dest = new String(bytes2, "utf-8");
- System.out.println(dest);
-
- }