【问题标题】:Unable to decode utf-8 using thai language?无法使用泰语解码 utf-8?
【发布时间】:2015-01-23 10:29:16
【问题描述】:

这是我的 JSP 页面:

<%-- 
    Document   : new jsp1
    Created on : Nov 24, 2014, 12:38:07 PM
    Author     : Java
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
 </head>
 <body>
   <%
   String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
   String result = java.net.URLEncoder.encode(msg, "UTF-8");
   System.out.println("The msg is "+result);
   String result1=java.net.URLDecoder.decode(result, "UTF-8");
   System.out.println("The decoded msg is "+result1);

   %>
 </body>
</html>

输出为206_John_help i m in trouble,delhi,???????_30.64741430_76.817313799

我总是得到?????? 而不是泰语字母。解码时如何获取泰语字母?

【问题讨论】:

    标签: java html encoder decoder


    【解决方案1】:

    问题不在于编码和解码消息,而在于服务器容器。似乎服务器无法正确显示特殊字符,因此无法从请求中处理它们。

    如果您在 JSP 页面本身中显示这些值,则一切正常。

    例子:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
     <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
     </head>
     <body>
       <%
       String msg="206_John_help i m in trouble,delhi,อินเดีย_30.64741430_76.817313799";
       System.out.println("The original message "+msg);
       String result = java.net.URLEncoder.encode(msg, "UTF-8");
       System.out.println("The msg is "+result);
       String result1=java.net.URLDecoder.decode(result, "UTF-8");
       System.out.println("The decoded msg is "+result1);
    
       %>
       Original message <%=msg %><br />
       Encrypted message <%=result %> <br />
       Decrypted message <%=result1 %>
    </body>
     </html>
    

    【讨论】:

    • 那么我应该如何解决服务器容器的问题?
    • 你使用的是什么服务器(tomcat、glassfish、jboss等)?
    • 请检查这个答案:stackoverflow.com/questions/6279504/… 特别是第二个,我认为是你的情况。
    猜你喜欢
    • 2021-03-22
    • 2021-05-14
    • 2015-07-19
    • 2011-01-01
    • 2017-10-06
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    相关资源
    最近更新 更多