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 請求 中文亂碼 -->

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM