Unable to decode utf-8 using thai language?

3.3k views Asked by At

This is my JSP page:

<%-- 
    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>

The output is 206_John_help i m in trouble,delhi,???????_30.64741430_76.817313799

I am always getting ?????? instead of thai alphabets. How can I get the Thai alphabets while decoding?

1

There are 1 answers

3
drgPP On BEST ANSWER

The problem is not on encoding and decoding the messages but in the server container. Seems that server cant display properly the special characters, so it can not treat them from request.

If you display the values in the JSP page itself, everything is working fine.

Example:

<%@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>