JS中解決中文亂碼的2種方法

  1.對象 request response 對象setCharacterEncoding=UTF-8

 1  <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"  %>
 2  <%
 3      //解決post/get 請求中文亂碼的方法
 4      request.setCharacterEncoding("UTF-8");
 5      response.setCharacterEncoding("UTF-8");
 6   %>  
 7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 8 <html>
 9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
11 <title>代碼段標籤</title>
12 </head>
13 <body>
14 <%! 
15     int name;
16     int password;
17  %>
18  <%
19      String name=request.getParameter("username");
20      String password =request.getParameter("pwd");
21      out.println("hello "+name+" success! "+"<br/>");
22      out.println("密碼泄露  "+password);
23   %>
24 </body>

  2. 方法二 (比較簡單)

  找到tomcat 配置文件 server.xml ,加入code: URIEncoding="utf-8"

1 <Connector port="8080" protocol="HTTP/1.1"
2                connectionTimeout="20000"
3                URIEncoding="utf-8"               
4                redirectPort="8443" />
5     <!-- URIEncoding="utf-8"  解決get/post 請求 中文亂碼 -->

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章